Skip to content

Instantly share code, notes, and snippets.

@samr28
Created July 12, 2016 14:12
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 samr28/1ac7f1029f6b19400ca89562fcba54df to your computer and use it in GitHub Desktop.
Save samr28/1ac7f1029f6b19400ca89562fcba54df to your computer and use it in GitHub Desktop.
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