Skip to content

Instantly share code, notes, and snippets.

@jscheel jscheel/blink2.ino Secret
Created Mar 31, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.