PDL_Async_Button is an Arduino library that allows you to detect short and long button presses asynchronously. This library helps you handle button presses without blocking your main program loop.
- Detect short button presses
- Detect long button presses
- Asynchronous, non-blocking operation
- Download the library from the GitHub repository.
- Unzip the library and place it in the
libraries
folder of your Arduino sketchbook.
PDL_Async_Button(uint8_t pin);
Creates a button instance on the specified pin.
void setPin(uint8_t pin, uint8_t mode);
Sets the pin and its mode (HIGH or LOW).void setDebounceTime(uint32_t debounceTime);
Sets the debounce time in milliseconds.void setLongPressTime(uint32_t longPressTime);
Sets the long press time in milliseconds.void setShortPressCallback(void (*shortPressCallback)());
Sets the callback function for short press detection.void setLongPressCallback(void (*longPressCallback)());
Sets the callback function for long press detection.void init();
Initializes the button.void update();
Updates the button state. Call this method in yourloop()
.uint8_t getState(int *shortPressCount, int *longPressCount);
Gets the current state of the button along with the counts of short and long presses.bool shortPress();
Returnstrue
if a short press is detected.bool longPress();
Returnstrue
if a long press is detected.
This library is licensed under the MIT License. See LICENSE for more details.
Feel free to submit issues or pull requests for any bugs or feature requests.
Developed by Xuteng Lin.