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
SeqButtoninstance (calledsbbelow) - 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 (NULLwhen no callback needed)cbckOFF: callback function on release (NULLwhen no callback needed)repeat: callback called repeatedly when set to truelogic: Button logic:LOWfor NO /HIGHfor 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