int LedPin1 = 2; //pin of first led int LedPin2 = 3; //pin of second led int LedPin3 = 4; //etc. int LedPin4 = 5; int LedPin5 = 6; const int ButtonPin = 8; // pin of the button //state van het knopje boolean old_val = LOW; //welk led lampje is aan int LightPos = 0; int pause = 0; //the score int score = 0; long lastMove = millis(); // new game void newGame() { LightPos = 0; //speed of the lights pause = 100; Serial.println("New Game: Score 0"); } //to move the position of the light void move(int LightPos) { for (int x = LedPin1; x <= LedPin5;x++) { digitalWrite(x, LOW); } digitalWrite(LightPos + 1, HIGH); } void setup() { // put your setup code here, to run once: pinMode(LedPin1, OUTPUT); pinMode(LedPin2, OUTPUT); pinMode(LedPin3, OUTPUT); pinMode(LedPin4, OUTPUT); pinMode(LedPin5, OUTPUT); pinMode(ButtonPin, INPUT); Serial.begin(9600); //start nieuw spel newGame(); } void loop() { // put your main code here, to run repeatedly: if(millis() - lastMove >= pause) { lastMove = millis(); LightPos++; if(LightPos >= 6) LightPos = 1; move(LightPos); } //if the button is pressed here it will add the score and stay on the led for a short period //to show you which one was pressed if(digitalRead(ButtonPin) == HIGH && old_val == LOW) { switch (LightPos) { case 1: { score += 10; delay(400); digitalWrite(LedPin1, HIGH); } break; case 2: { score += 25; delay(400); digitalWrite(LedPin2, HIGH); } break; case 3: { score += 100; delay(400); digitalWrite(LedPin3, HIGH); } break; case 4: { score += 25; delay(400); digitalWrite(LedPin4, HIGH); } break; case 5: { score += 10; delay(400); digitalWrite(LedPin5, HIGH); } break; } Serial.print("Score: "); Serial.println(score); Serial.print("LightPos: "); Serial.println(LightPos); } }