From a953f7d2d9428b8b112b0c1a719dfd01115195f7 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 6 Jan 2023 18:08:41 +0100 Subject: [PATCH] Reduce sensitivity --- src/config.h | 2 ++ src/main.cpp | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index 3a90d85..44803fa 100644 --- a/src/config.h +++ b/src/config.h @@ -20,6 +20,8 @@ #define LED 2 #define BUTTON 33 +#define DEBOUNCE_DELAY 1000 + // Screen #define SSD1306_NO_SPLASH #define SCREEN_WIDTH 128 diff --git a/src/main.cpp b/src/main.cpp index 824a0a1..0e2308f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include "config.h" byte buttonLastState = HIGH; +long lastDebounceTime = 0; void setup() { @@ -43,9 +44,12 @@ void setup() void loop() { - byte buttonCurrentState = digitalRead(BUTTON); - if (buttonCurrentState == LOW && buttonLastState == HIGH) - play(); - buttonLastState = buttonCurrentState; + if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY) + { + byte buttonCurrentState = digitalRead(BUTTON); + if (buttonCurrentState == LOW && buttonLastState == HIGH) + play(); + buttonLastState = buttonCurrentState; + } audio.loop(); }