https://github.com/smfsw/seqbutton
Handling filtered button pushes with callbacks for Arduino
https://github.com/smfsw/seqbutton
arduino arduino-library button callback filter handler pin
Last synced: 2 months ago
JSON representation
Handling filtered button pushes with callbacks for Arduino
- Host: GitHub
- URL: https://github.com/smfsw/seqbutton
- Owner: SMFSW
- License: bsd-3-clause
- Created: 2017-03-20T22:33:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-05-06T21:51:31.000Z (about 1 year ago)
- Last Synced: 2025-08-27T12:13:25.612Z (10 months ago)
- Topics: arduino, arduino-library, button, callback, filter, handler, pin
- Language: C++
- Size: 708 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SeqButton
[](https://github.com/SMFSW)

[](LICENSE)
[](https://www.codefactor.io/repository/github/smfsw/seqbutton)

[](https://smfsw.github.io/SeqButton)
[](ReleaseNotes.md)
Sequential Button Arduino Library
Handling filtered button press with callbacks for push (with or without repeat) and release, logic, filtering time and sequences.
## Usage
- Declare a `SeqButton` instance (called `sb` 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 connected
- `cbckON`: 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 true
- `logic`: 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()` or `sb.getButton()` can be used to get current button state at any time
- `sb.getPin()` can be used to check pin assigned to instance
- `sb.getHoldTime()` can be used on a release callback to get hold duration of button
## Examples included
- [AdvancedButton.ino](examples/AdvancedButton/AdvancedButton.ino): Toggle a LED at each button press (showing all init parameters)
- [CallbacksExample.ino](examples/CallbacksExample/CallbacksExample.ino): Toggle a LED at each push on button 1 and at each release on button 2
- [CombinationExample.ino](examples/CombinationExample/CombinationExample.ino): Prints messages to serial depending on combination read from inputs
- [OffTimerButton.ino](examples/OffTimerButton/OffTimerButton.ino): Turns a LED on when button is pressed, turning off 1s after release
- [RepeatButton.ino](examples/RepeatButton/RepeatButton.ino): Toggle a LED repeatedly when button pressed
- [SequenceExample.ino](examples/SequenceExample/SequenceExample.ino): Prints messages to serial depending on sequence read from inputs
- [TimingExample.ino](examples/TimingExample/TimingExample.ino): Toggle a LED at each push on button 1 or 2 if held for more than 1s
- [ToggleButton.ino](examples/ToggleButton/ToggleButton.ino): Toggle a LED at each button press