From 5675bf44b8f29229e7b949da496716d8a1cd896e Mon Sep 17 00:00:00 2001 From: talksik Date: Thu, 25 Jan 2024 13:46:59 -0800 Subject: [PATCH] avoiding duplicate reads --- Main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Main.c b/Main.c index 60351cc..da1e674 100644 --- a/Main.c +++ b/Main.c @@ -1,6 +1,7 @@ #include #include +#include // these are based on the wiringPi pin numbers #define YELLOW_PIN 26 // GPIO 12 @@ -43,15 +44,18 @@ int main(int argc, char *argv[]) pullUpDnControl(BUTTON_PIN, PUD_UP); enum LED_STATE ledState = BLANK; + bool buttonPressed = false; while (1) { - if (digitalRead(BUTTON_PIN) == LOW) + if (digitalRead(BUTTON_PIN) == LOW && !buttonPressed) { ledState = (ledState + 1) % NUM_LEDS; + buttonPressed = true; } else { + buttonPressed = false; continue; }