-
-
Save jscheel/9bed231f26e5b1220969605c8655b7fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dummy.h> | |
const int SWITCH_PIN = 0; | |
const long BLINK_INTERVAL = 250; | |
int ledState = LOW; | |
bool isBlinking = false; | |
unsigned long previousMillis = 0; | |
void setup() { | |
pinMode(LED_BUILTIN, OUTPUT); | |
pinMode(SWITCH_PIN, INPUT_PULLUP); | |
} | |
void loop() { | |
if (digitalRead(SWITCH_PIN) == LOW) { | |
if (isBlinking == false) { | |
previousMillis = 0; | |
} | |
isBlinking = true; | |
unsigned long currentMillis = millis(); | |
if(currentMillis - previousMillis >= BLINK_INTERVAL) { | |
previousMillis = currentMillis; | |
if (ledState == LOW) { | |
ledState = HIGH; | |
} | |
else { | |
ledState = LOW; | |
} | |
digitalWrite(LED_BUILTIN, ledState); | |
} | |
} | |
else { | |
isBlinking = false; | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment