int BUTTON = 0; // Pin 0. PA06. Button. int LEDR1 = 1; // Pin 1. PA7. Red led to match with the button. int LEDR2 = 2; // Pin 2. PA1. Second red LED starting from the bottom. int LEDR3 = 3; // Pin 3. PA2. Third red LED starting from the bottom. int LEDV = 4; // Pin 4. PA3. Green led which ligths up when you hit it right. int VELOCIDAD = 100; //Game speed bool LEDR1StateRead; //Stores the state of the Led1 bool LEDR2StateRead; //Stores the state of the Led2 bool LEDR3StateRead; //Stores the state of the Led3 //setLedRx is the digitalWrite function but making the state of the Led as an input variable, to store it. //LEDRxStateRead = LEDRxState is made because arduino does not let me use the fx variable outside of it; void setLedR1(bool LEDR1State){ digitalWrite(LEDR1, LEDR1State); LEDR1StateRead = LEDR1State; } void setLedR2(bool LEDR2State){ digitalWrite(LEDR2, LEDR2State); LEDR2StateRead = LEDR2State; } void setLedR3(bool LEDR3State){ digitalWrite(LEDR3, LEDR3State); LEDR3StateRead = LEDR3State; } void WinLose(int RESULTADO) { if (RESULTADO == 1){ //If you have hitted it right for (int x = 0; x < 4; x++){ digitalWrite(LEDV, HIGH); delay(200); digitalWrite(LEDV, LOW); delay(100); } } if (RESULTADO == 2){ //If you have hitted it wrong (Led2) for (int x = 0; x < 4; x++){ setLedR1(HIGH); setLedR2(HIGH); setLedR3(HIGH); delay(200); setLedR1(LOW); setLedR3(LOW); delay(100); } } if (RESULTADO == 3){ //If you have hitted it wrong (Led3) for (int x = 0; x < 4; x++){ setLedR1(HIGH); setLedR2(HIGH); setLedR3(HIGH); delay(200); setLedR1(LOW); setLedR2(LOW); delay(100); } } } void setup() { pinMode(BUTTON, INPUT); pinMode(LEDR1, OUTPUT); pinMode(LEDR2, OUTPUT); pinMode(LEDR3, OUTPUT); pinMode(LEDV, OUTPUT); } void loop() { setLedR1(HIGH); if (LEDR1StateRead == HIGH){ //If first red led is on if (digitalRead(BUTTON) == HIGH) //If the button is pressed WinLose(1); } delay(VELOCIDAD); setLedR1(LOW); setLedR2(HIGH); if (LEDR2StateRead == HIGH){ //If second red led is on if (digitalRead(BUTTON) == HIGH) //If the button is pressed WinLose(2); } delay(VELOCIDAD); setLedR2(LOW); setLedR3(HIGH); if (LEDR3StateRead == HIGH){ //If third red led is on if (digitalRead(BUTTON) == HIGH) //If the button is pressed WinLose(3); } delay(VELOCIDAD); setLedR3(LOW); }