12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include <Button.h>
- #include <ButtonEventCallback.h>
- #include <BasicButton.h>
- BasicButton button = BasicButton(5);
- void setup(){
-
- Serial.begin(9600);
-
- button.onPress(onButtonPressed);
-
- button.onHoldRepeat(1000, 500, onButtonHeld);
-
- button.onRelease(onButtonReleased);
- }
- void loop(){
-
- button.update();
- }
- 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");
- }
|