Reaction Game with Arcade LED Buttons

Goodday programmers! I need your help for my graduation project. I've developed a kinetic energy module which will power an interactive game panel.

This game panel consists of 4 LED arcade buttons which will light up one by one in a random order. The player has to hit the illuminated button as fast as possible. When hit, the next one will light up and so on.

I'm trying to figure out a way to program the LED's and the buttons to work as stated above. I'm not a programmer and this is my first arduino project so any help is welcome! ^^

Schematic overview:

  • 4 Arcade Buttons with built in LED's
  • One button lights up (randomly selected)
  • After this particullary button is hit, the light goes out
  • interval of 1 second where no lights are on
  • Again another random button (could be the same as before) lights up
  • If the wrong button gets hit, the illuminated button stays lit until this button is hit.

I've got the code as far as defining the in- and outputs but I get stuck at randomly powering the LEDS. Hope to hear from someone soon! ^^

I've got the code as far as defining the in- and outputs but I

forgot to post it.

I get stuck at randomly powering the LEDS.

That's so trivial, I can't imagine why.

Hope to hear from someone soon! ^^

I'll bet that this is not what you wanted to hear.

In the interest of helping you graduate I wrote some skeleton code that will write to pins selected at random.

If you want to look at it my advice is to first just upload it to the Arduino and open the serial monitor (set for 9600 baud). Type a character and click Send and see what it says. It will choose a new random pin every time a character is sent.

If you want to use the code it’s up to you to set it up for how your project is wired, add comments on what the code is doing and integrate the button press logic.

/*
   - light random LED
   - wait for input from Serial monitor
   - turn off LED
   - wait 1 second
   - repeat
*/

const int NUM_BUTTONS = 4;
int ledPins[] = {2, 3, 4, 7};  // see Examples=>Control=>Arrays in IDE

int lastLedIdx;

void setup()
{

  for (int i = 0; i < NUM_BUTTONS; i++) pinMode(ledPins[i], OUTPUT);

  Serial.begin(9600);
  Serial.println("Starting game ...");

  lastLedIdx = random(NUM_BUTTONS);
  digitalWrite(ledPins[lastLedIdx], HIGH);
  Serial.print("Button "); Serial.print(lastLedIdx); Serial.print(" is lit on pin "); Serial.println(ledPins[lastLedIdx]);

}

void loop()
{

  // simulate button press by entering anything in serial monitor, for testing
  if ( Serial.available() ) {

    while ( Serial.available() ) Serial.read(); // clear serial, for testing

    // assume correct button is pressed, for testing


    digitalWrite(ledPins[lastLedIdx], LOW);

    delay(1000);

    lastLedIdx = random(NUM_BUTTONS);
    digitalWrite(ledPins[lastLedIdx], HIGH);
    Serial.print("Button "); Serial.print(lastLedIdx); Serial.print(" is lit on pin "); Serial.println(ledPins[lastLedIdx]);

  } // if


}