Skip to content

Instantly share code, notes, and snippets.

@jscheel
Created March 31, 2017 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jscheel/9bed231f26e5b1220969605c8655b7fa to your computer and use it in GitHub Desktop.
Save jscheel/9bed231f26e5b1220969605c8655b7fa to your computer and use it in GitHub Desktop.
#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