Created
July 12, 2016 14:12
-
-
Save samr28/1ac7f1029f6b19400ca89562fcba54df 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
const int LED_PIN = 13; | |
bool isOk = false; | |
bool lose = false; | |
int counter = 0; | |
int millis1 = 0; | |
int millis2 = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(LED_PIN, OUTPUT); | |
digitalWrite(LED_PIN, LOW); | |
attachInterrupt(0, buttonPressed, RISING); | |
} | |
void loop() { | |
if (!isOk && !lose) { | |
int delayTime = (random(1,10))*1000; | |
delay(delayTime); | |
if (!lose) { | |
digitalWrite(LED_PIN, HIGH); | |
millis1 = millis(); | |
isOk = true; | |
} | |
} | |
else if (counter >= 5) { | |
digitalWrite(LED_PIN, HIGH); | |
delay(2000); | |
digitalWrite(LED_PIN, LOW); | |
lose = false; | |
} | |
else if (lose) { | |
digitalWrite(LED_PIN, HIGH); | |
delay(1000); | |
digitalWrite(LED_PIN, LOW); | |
delay(1000); | |
counter++; | |
} | |
} | |
void buttonPressed() { | |
if (isOk) { | |
Serial.println("WIN"); | |
digitalWrite(LED_PIN, LOW); | |
millis2 = millis(); | |
Serial.print("Time: "); | |
Serial.println(millis2-millis1); | |
lose = false; | |
counter = 0; | |
} | |
else { | |
Serial.println("LOSE"); | |
lose = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment