Multiple minigames in particular order

Goodevening people,

I'm stuck on a project, which is about to meet its deadline. Because of an unfortunate accident my brain functionality has suffert quite blow, and quite a downgrade. This has frustrated me for weeks now, beacause i cannot seem to move on where i left off... I just don't understand it all anymore, and i completely wrecked my original code. This is the reason why i'm asking you folks for help.

I made a fysical room with 6 very bright RGB leds on the wall, accompanied by 6 pushbuttons, each has a white led in it.

What should it do?
At first the lights burn RED, made to do so through the setup. When all the buttons are pressed, the lights must go off. When this has happened, a new minigame starts:

Each light must be set to a particular color (eg Red, Green or Blue) by pushing the buttons underneath. Each push changes the color of the LED above. When the order is correct, next minigame!

I was programming in the right direction, but i'm totally lost right now and need to learn things all over again. You almost cannot imagine the frustration of not knowing things that where simple to you before, so i really hope you guys and girls might push me in the right direction.

(current code not on this system, will be posting it tomorrow. Though its completely useless now...)

Thank you so, so much!

Thornberg:
a project, which is about to meet its deadline

That's a good thing. Missing a deadline is a bad thing.

There's not much we can suggest without seeing the code, but there's a few things missing in your specification.

  1. How do we know when a 'game' begins?
  2. How do we know what the goal of each game is? The list of colours. Is that a list on paper or does the Arduino show you in some way?
    It is not clear to me if there's 6 RGB LEDs or 12 of them, with 6 in the buttons and 6 on the wall?
  3. Do you have a nice 'success' animation that gives the player a little dose of endorphins (happiness) so they keep playing the game?

Pardon my English, it could be a lot better but it's not my native :slight_smile:

  1. The game begins at the very start, that is obvious to the players. (also, see 3)

  2. There are 6 RGB lights on the wall (24V RGB strips build into an industrial housing, controlled via mosfets). Underneath each light, there is a Arcade Button with a white led in it.

The goal is to be found out by the players. At first, the button turns off the light. It cannot be turned on again, so the logic thing to try is to turn them all off. When they did that (see 3) the next game commenses, and each push on the button turns the light on to Red, Green or Blue. When all the lights are Blue, for example (see 3) the next game begins. And so on.

  1. There is a nice succes animation. Also, there is a failure animation, but thats not important now. The lights blink green and the arduino sends a PWM signal to another microcontroller that plays a sound and does some other things. (if you want to know this trivia, read on: There is a door in the room, locked by 6 locks. Each time a game is finished succesfully, the other controller recieves the signal, plays the sound and lets one of the 6 keys fall from the ceiling (via servo's). After 6 games, the players have all the keys and the door can be opened to the next room.

The miniature of the game: The red leds correspond with the white leds inside the (arcade) pushbuttons on the wall. Ofcourse, the black buttons here represent those arcade buttons. The RGB leds on the right are the RGB lights above the buttons on the Wall. The most left button belongs with the most left RGB LED, etc.

Hope you might help me out! Thanks a lot! See the setup code in the next post.

(note: I'm not lazy, i was working on this for almost 2 months, the room is already build, but I just cannot get the code right anymore. I've been learning it all over again for 4 weeks now, but i cannot wrap my head around it anymore. Hope you understand, I'm very happy to learn again!

This is the setup code: It's long, be aware, and it includes a test to see if all the lights are working. It also includes the succes and failure animation. The rest of the code is completely wasted after me trying to do right, ending up ruining everything.

// 6 RGB lights (a, b, c, d, e & f)
const int aRed = 22;
const int aGreen = 23;
const int aBlue = 24;

const int bRed = 25;
const int bGreen = 26;
const int bBlue = 27;

const int cRed = 28;
const int cGreen = 29;
const int cBlue = 30;

const int dRed = 31;
const int dGreen = 32;
const int dBlue = 33;

const int eRed = 34;
const int eGreen = 35;
const int eBlue = 36;

const int fRed = 37;
const int fGreen = 38;
const int fBlue = 39;

// buttons under the lights (Button 1 goes under RGB light a, 2 under b, etc)
const int Button1 = A10;
const int Button2 = A11;
const int Button3 = A12;
const int Button4 = A13;
const int Button5 = A14;
const int Button6 = A15;

// white LED's inside the buttons
const int ledButton1 = 42;
const int ledButton2 = 43;
const int ledButton3 = 44;
const int ledButton4 = 45;
const int ledButton5 = 46;
const int ledButton6 = 47;

// PWM output to other controller
int lox = 2;

// variable for reading the pushbutton status
int buttonState = 0;

//
//
//

void setup() {
  // initialize digital pin 22 to 39 as outputs.
  pinMode(aRed, OUTPUT);
  pinMode(aGreen, OUTPUT);
  pinMode(aBlue, OUTPUT);

  pinMode(bRed, OUTPUT);
  pinMode(bGreen, OUTPUT);
  pinMode(bBlue, OUTPUT);

  pinMode(cRed, OUTPUT);
  pinMode(cGreen, OUTPUT);
  pinMode(cBlue, OUTPUT);

  pinMode(dRed, OUTPUT);
  pinMode(dGreen, OUTPUT);
  pinMode(dBlue, OUTPUT);

  pinMode(eRed, OUTPUT);
  pinMode(eGreen, OUTPUT);
  pinMode(eBlue, OUTPUT);

  pinMode(fRed, OUTPUT);
  pinMode(fGreen, OUTPUT);
  pinMode(fBlue, OUTPUT);
  
  // initialize digital pin 42 to 47 as outputs.
  pinMode(ledButton1, OUTPUT);
  pinMode(ledButton2, OUTPUT);
  pinMode(ledButton3, OUTPUT);
  pinMode(ledButton4, OUTPUT);
  pinMode(ledButton5, OUTPUT);
  pinMode(ledButton6, OUTPUT);

  // initialize analog pin 10 to 15 as inputs.
  pinMode(Button1, INPUT);
  pinMode(Button2, INPUT);
  pinMode(Button3, INPUT);
  pinMode(Button4, INPUT);
  pinMode(Button5, INPUT);
  pinMode(Button6, INPUT);

  // initialize pin 2 for PWM output to sound and servo controller
  pinMode(lox, OUTPUT);

// test RED RGB
digitalWrite(aRed, HIGH);digitalWrite(bRed, HIGH);digitalWrite(cRed, HIGH);digitalWrite(dRed, HIGH);digitalWrite(eRed, HIGH);digitalWrite(fRed, HIGH);
delay(1000);
digitalWrite(aRed, LOW);digitalWrite(bRed, LOW);digitalWrite(cRed, LOW);digitalWrite(dRed, LOW);digitalWrite(eRed, LOW);digitalWrite(fRed, LOW);

// test GREEN RGB
digitalWrite(aGreen, HIGH);digitalWrite(bGreen, HIGH);digitalWrite(cGreen, HIGH);digitalWrite(dGreen, HIGH);digitalWrite(eGreen, HIGH);digitalWrite(fGreen, HIGH);
delay(1000);
digitalWrite(aGreen, LOW);digitalWrite(bGreen, LOW);digitalWrite(cGreen, LOW);digitalWrite(dGreen, LOW);digitalWrite(eGreen, LOW);digitalWrite(fGreen, LOW);

// test BLUE RGB
digitalWrite(aBlue, HIGH);digitalWrite(bBlue, HIGH);digitalWrite(cBlue, HIGH);digitalWrite(dBlue, HIGH);digitalWrite(eBlue, HIGH);digitalWrite(fBlue, HIGH);
delay(1000);
digitalWrite(aBlue, LOW);digitalWrite(bBlue, LOW);digitalWrite(cBlue, LOW);digitalWrite(dBlue, LOW);digitalWrite(eBlue, LOW);digitalWrite(fBlue, LOW);

// test button LED's
digitalWrite(ledButton1, HIGH);digitalWrite(ledButton2, HIGH);digitalWrite(ledButton3, HIGH);digitalWrite(ledButton4, HIGH);digitalWrite(ledButton5, HIGH);digitalWrite(ledButton6, HIGH);
delay(1000);
digitalWrite(ledButton1, LOW);digitalWrite(ledButton2, LOW);digitalWrite(ledButton3, LOW);digitalWrite(ledButton4, LOW);digitalWrite(ledButton5, LOW);digitalWrite(ledButton6, LOW);

// test flash GOOD
delay(1000);

digitalWrite(aGreen, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aGreen, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bGreen, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bGreen, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cGreen, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cGreen, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dGreen, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dGreen, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eGreen, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eGreen, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fGreen, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fGreen, LOW);digitalWrite(ledButton1, LOW);

digitalWrite(aGreen, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aGreen, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bGreen, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bGreen, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cGreen, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cGreen, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dGreen, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dGreen, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eGreen, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eGreen, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fGreen, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fGreen, LOW);digitalWrite(ledButton1, LOW);

digitalWrite(aGreen, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aGreen, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bGreen, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bGreen, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cGreen, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cGreen, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dGreen, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dGreen, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eGreen, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eGreen, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fGreen, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fGreen, LOW);digitalWrite(ledButton1, LOW);

// test flash BAD
delay(1000);

digitalWrite(aRed, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aRed, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bRed, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bRed, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cRed, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cRed, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dRed, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dRed, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eRed, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eRed, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fRed, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fRed, LOW);digitalWrite(ledButton1, LOW);

digitalWrite(aRed, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aRed, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bRed, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bRed, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cRed, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cRed, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dRed, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dRed, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eRed, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eRed, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fRed, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fRed, LOW);digitalWrite(ledButton1, LOW);

digitalWrite(aRed, HIGH);digitalWrite(ledButton6, HIGH);
delay(70);
digitalWrite(aRed, LOW);digitalWrite(ledButton6, LOW);
digitalWrite(bRed, HIGH);digitalWrite(ledButton5, HIGH);
delay(70);
digitalWrite(bRed, LOW);digitalWrite(ledButton5, LOW);
digitalWrite(cRed, HIGH);digitalWrite(ledButton4, HIGH);
delay(70);
digitalWrite(cRed, LOW);digitalWrite(ledButton4, LOW);
digitalWrite(dRed, HIGH);digitalWrite(ledButton3, HIGH);
delay(70);
digitalWrite(dRed, LOW);digitalWrite(ledButton3, LOW);
digitalWrite(eRed, HIGH);digitalWrite(ledButton2, HIGH);
delay(70);
digitalWrite(eRed, LOW);digitalWrite(ledButton2, LOW);
digitalWrite(fRed, HIGH);digitalWrite(ledButton1, HIGH);
delay(70);
digitalWrite(fRed, LOW);digitalWrite(ledButton1, LOW);



delay(1000);
}

//
//
//

void loop() {

}

OK, looks good so far. I would have used arrays but if you don't mind some copy-pasting, you can do it your way with ABCDEF.

This is a really big state machine. It's probably several state machines, one inside the other. The top level is the 'games'. The first game just flashes the lights. The others drop a key at each 'success'. Then you need another special game just for you to reset everything back and put the keys back in their places. That game might be controlled by the power switch.

The next level of state machine is the individual game. It allows the inputs to change until the correct combination is found.

Below that is the individual buttons and colours. Pushing the button cycles through 8 different colours until it gets back to the first one.

Can I assume that you have the 'success' animation and the servo dropping they key sorted out? It works mechanically and you can make one button drop one key?

Next, I would recommend working on the button state machine. Each button needs to remember what colour it's displaying. Each colour will have a defined 'next' when the button is pushed. I would use an array of colours numbered 0-7, or however many you want. You are going to need debouncing on the buttons. Look for tutorials on that.

Then step up to the next level: think about how you might store 6 different winning combinations of 6 colours. This will definitely be much easier with an array.