/* DESCRIPTION ==================== Reports through serial (57600 baud) the time since a button press (transition from HIGH to LOW). */ // Include the Bounce2 library found here : // https://github.com/thomasfredericks/Bounce-Arduino-Wiring #include #define BUTTON_PIN 2 #define LED_PIN 13 #define DEBOUNCE_TIME 5 #define HOLD_TIME 1000 #define RETRIGGER_TIME 100 // Instantiate a Bounce object with default values Bounce debouncer(BUTTON_PIN); // Or set your own values when instantiating Bounce object // Bounce debouncer(BUTTON_PIN,DEBOUNCE_TIME, RETRIGGER_TIME, HOLD_TIME); unsigned long buttonPressTimeStamp; void setup() { Serial.begin(57600); // Setup the button with an internal pull-up : pinMode(BUTTON_PIN,INPUT_PULLUP); // Setup the LED : pinMode(LED_PIN,OUTPUT); } void loop() { // Update the Bounce instance : debouncer.update(); // Call code if Bounce fell (transition from HIGH to LOW) : if ( debouncer.fell() ) {; Serial.println( millis()-buttonPressTimeStamp ); buttonPressTimeStamp = millis(); } }