avoiding duplicate reads

This commit is contained in:
talksik
2024-01-25 13:46:59 -08:00
parent de387a62dc
commit 5675bf44b8
+5 -1
View File
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <wiringPi.h>
#include <stdbool.h>
// 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;
}