/* Constants - define pin numbers for LEDs,
buttons and speaker, and also the game tones: */
const uint8_t ledPins[] = {9, 10, 11, 12};
const uint8_t buttonPins[] = {2, 3, 4, 5};
int score = 0;
int timer = 30;
bool playing = false;
void setup() {
Serial.begin(9600);
for (byte i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
pinMode(buttonPins[i], INPUT);
digitalWrite(ledPins[i],LOW);
digitalWrite(buttonPins[i],LOW);
}
randomSeed(analogRead(0));
}
void loop() {
Serial.println("Are you ready to play the game?");
delay(3000);
if (Serial.available() == 0) {
playing = true;
}
while (playing) {
int randNumber;
randNumber = random(4);
digitalWrite(ledPins[randNumber], HIGH);
if (digitalRead(buttonPins[randNumber]) == HIGH) {
// turn LED off:
digitalWrite(ledPins[randNumber],LOW);
score += 1;
Serial.println("Your score is:");
Serial.println(score);
}
if (score==30) {
Serial.println("GAME OVER!");
Serial.println("Your score is:");
Serial.println(score);
playing = false;
}
delay(1000);
}
}