Sequential Button Arduino Library
Handling filtered button press with callbacks for push (with or without repeat) and release, logic, filtering time and sequences.
- Declare a
SeqButton
instance (calledsb
below) - Create callback function(s) of type
void func()
- Initialize instance with
sb.init(uint8_t pin, void (*cbckON)(SeqButton*), void (*cbckOFF)(SeqButton*), bool repeat, bool logic=LOW, uint16_t filter=50)
pin
: pin on which button is connectedcbckON
: callback function on press (NULL
when no callback needed)cbckOFF
: callback function on release (NULL
when no callback needed)repeat
: callback called repeatedly when set to truelogic
: Button logic:LOW
for NO /HIGH
for NC (internal pullup for input is enabled)filter
: filtering time (in ms)
- Call the handler in a loop using
sb.handler()
-> handler returns the current button value (if needed) sb.getState()
orsb.getButton()
can be used to get current button state at any timesb.getPin()
can be used to check pin assigned to instancesb.getHoldTime()
can be used on a release callback to get hold duration of button
- AdvancedButton.ino: Toggle a LED at each button press (showing all init parameters)
- CallbacksExample.ino: Toggle a LED at each push on button 1 and at each release on button 2
- CombinationExample.ino: Prints messages to serial depending on combination read from inputs
- OffTimerButton.ino: Turns a LED on when button is pressed, turning off 1s after release
- RepeatButton.ino: Toggle a LED repeatedly when button pressed
- SequenceExample.ino: Prints messages to serial depending on sequence read from inputs
- TimingExample.ino: Toggle a LED at each push on button 1 or 2 if held for more than 1s
- ToggleButton.ino: Toggle a LED at each button press
Doxygen doc can be generated using "Doxyfile".
See release notes