The OneButtonTiny class is a lightweight version of the standard OneButton library designed for environments with very limited memory. It provides the same core functionality: detecting single clicks, double clicks, multi-clicks, and long presses on a single button.
Initialization
Use the constructor to define the hardware pin and electrical configuration:
pin: The digital pin number.activeLow: Set to true if the button connects the pin to GND when pressed (default: true).pullupActive: Set to true to enable the internal pull-up resistor (default: true).
Event Handling
You can attach callback functions to specific button events using attachClick(), attachDoubleClick(), attachMultiClick(), and attachLongPressStart().
#include <OneButtonTiny.h>
// Callback function
void myClickCallback() {
Serial.println("Button clicked!");
}
// Initialize on pin 2, active low, with internal pullup
OneButtonTiny button(2, true, true);
void setup() {
button.attachClick(myClickCallback);
}
void loop() {
button.tick();
}