1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #include <Button.h>
- #include <ButtonEventCallback.h>
- #include <PushButton.h>
- #include <Bounce2.h>
- PushButton button = PushButton(5);
- void setup(){
-
- Serial.begin(9600);
-
- button.configureButton(configurePushButton);
-
- button.onPress(onButtonPressed);
-
- button.onHoldRepeat(1000, 500, onButtonHeld);
-
- button.onRelease(onButtonReleased);
- }
- void loop(){
-
- button.update();
- }
- void configurePushButton(Bounce& bouncedButton){
-
- bouncedButton.interval(15);
- }
- void onButtonPressed(Button& btn){
- Serial.println("button pressed");
- }
- void onButtonHeld(Button& btn, uint16_t duration, uint16_t repeatCount){
- Serial.print("button has been held for ");
- Serial.print(duration);
- Serial.print(" ms; this event has been fired ");
- Serial.print(repeatCount);
- Serial.println(" times");
- }
- void onButtonReleased(Button& btn, uint16_t duration){
- Serial.print("button released after ");
- Serial.print(duration);
- Serial.println(" ms");
- }
|