Arduino library for handling multiple buttons with press, long press, and release detection using a simple callback mechanism.
- Supports up to 10 buttons (default, configurable via
MAX_BUTTONS). - Detects:
BTN_PRESSEDBTN_LONG_PRESS(default 1000 ms, configurable viaLONG_PRESS_MS)BTN_RELEASED
- Callback-based interface.
- Lightweight C core with Arduino C++ wrapper.
- Uses
INPUTmode with default LOW (not pressed) and HIGH (pressed).
- Download or clone this repository into your Arduino
librariesfolder. - Restart the Arduino IDE.
- Open File → Examples → ActionButtons to try the included demos.
#include <ActionButtons.h>
void buttons_activated_callback(uint8_t pin, btn_action_t action) {
if (pin == 2 && action == BTN_PRESSED) {
Serial.println("Button 2 PRESSED");
}
}
uint8_t buttons[] = { 2, 3, 4 };
ActionButtons btns(buttons, 3, &buttons_activated_callback);
void setup() {
Serial.begin(9600);
}
void loop() {
btns.update();
delay(100);
}This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 Volodymyr Kumpan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.