How to rebuild this childrens museum game

Hi there,
For a lokal museum ( MOT Grimbergen, Belgium ) I want to repair some old mechanical game.
It has 3 colums of data and the children have to combine the right items tot get a correct answer.

for example: A cheep produces wool and we can make a glove from wool
So the have to combine the 3 from a list ( 3 times 6 choices )

I can rebuild the device ( witch motion detection, speech and so on ), but I really don't understand how to program the readout from the 18 buttons. Children do not always work from left to right, and there I'm stuck. Also if they push more than 1 button in the same colum makes it too difficult for me.
Can someone get me started in how to manage this?

Thx in advance, Dierik

Hi - we are missing information on how the setup works.
do you have physical buttons that kids press? are they momentary?
any picture / schematic / ... would help provide more meaningful guidance

The existing hardware is compleet broken after a flood. So I have to start from scratch. I was thinking to use big pushbuttons with buildin LED that lights up when they push.

Before programming anything, I think you should have it very clear for yourself how the device should actually work:

Children do not always work from left to right, and there I'm stuck. Also if they push more than 1 button in the same column makes it too difficult for me.

What do you want the machine to do in those kind of cases? Write down the different situations that can arise, and determine what the machine should do in those cases. From there you will have already a good starting point to start programming, because you know what behavior you want to achieve.

so if I get that right you have 18 buttons arranged in a 3 x 6 grid

Rules:

pressing a button would light up that button and if a button is already lit in a column, it would switch off (only one button ON per column).

pressing a lit button would switch it off

if you have a match of 3 buttons being lit (one in each column) according to some rules ("Sheep" "Wool" "Gloves") then it's a win, so you show some animation / sound and then turn off all the LEDs and the game is ready to start again

You need to decide what to do if there is no winning combination (turn everything off, or just not do anything until there is a match)

So you need 18 pins for the buttons (unless you use a matrix approach), 18 pins to command the LEDs, and some other (music, voice, sound) devices. An Arduino Mega could provide enough pins for that

Using a button library would make your life easier. I like the GitHub - bricoleau/easyRun: Doing sereval things at the same time becomes so easy collection of tools.

you could think of something like this for the structure of the code:

#include <easyRun.h>  // https://github.com/bricoleau/easyRun

const byte colCount = 3;
const byte rowCount = 6;

button buttons[colCount][rowCount] = {
  {{ 2}, { 3}, { 4}, { 5}, { 6}, { 7}}, // left column
  {{A0}, {A1}, {A2}, {A3}, {A4}, {A5}}, // center column
  {{14}, {15}, {16}, {17}, {18}, {19}}, // right column
};

const byte ledsPin[colCount][rowCount] = {
  {20, 21, 22, 23, 24, 25}, // left column
  {26, 27, 28, 29, 30, 31}, // center column
  {32, 33, 34, 35, 36, 37}, // right column
};

byte ledsState[colCount][rowCount] = {LOW};

// indexes of winning combinations (starting at 0)
const byte solutions[rowCount][colCount] = {
  {0, 2, 1}, // 1st button of left col + 3rd button of center col + second button of right col
  {1, 0, 2},
  {2, 1, 5},
  {3, 5, 0},
  {4, 3, 4},
  {5, 4, 3},
};
const byte solutionsCount = sizeof solutions / sizeof solutions[0];
const byte emptyAnswer = 0xFF;
byte currentAnwer[colCount] = {emptyAnswer};

void resetGame() {
  for (byte r = 0; r < rowCount; r++)
    for (byte c = 0; c < colCount; c++) {
      ledsState[c][r] = LOW;
      digitalWrite(ledsPin[c][r], LOW);
    }
  memset(currentAnwer, emptyAnswer, colCount);
}

void win() {
  Serial.println(F("Success"));
  resetGame();
}



void testButtons() {
  easyRun();
  for (byte r = 0; r < rowCount; r++)
    for (byte c = 0; c < colCount; c++) {
      if (buttons[c][r]) {
        Serial.print(F("button @ ("));
        Serial.print(c); Serial.write(','); Serial.print(r);
        Serial.println(F(") pressed"));
        // check if that button was active
        if (ledsState[c][r] == HIGH) {
          currentAnwer[c] = emptyAnswer;
          ledsState[c][r] = LOW;
          digitalWrite(ledsPin[c][r], LOW);
        } else {
          currentAnwer[c] = r;
          ledsState[c][r] = HIGH;
          digitalWrite(ledsPin[c][r], HIGH);

          // check in the column c if another button has been pressed
          for (byte i = 0; i < rowCount; i++) {
            if ((i != r) && (ledsState[c][i] == HIGH)) {
              // there was a previous button activated. Switch it off
              ledsState[c][i] = LOW;
              digitalWrite(ledsPin[c][i], LOW);
              break; // no need to go further, there should be only one
            }
          }
          // check if there is a winning combination
          for (byte i = 0; i < solutionsCount; i++) {
            if (memcmp(currentAnwer, solutions[i], colCount) == 0) {
              win();
              return;
            }
          }
        }
      }
    }
}

void setup() {
  for (byte r = 0; r < rowCount; r++)
    for (byte c = 0; c < colCount; c++) {
      pinMode(ledsPin[c][r], OUTPUT);
      digitalWrite(ledsPin[c][r], ledsState[c][r]);
    }
  Serial.begin(115200); Serial.println();
}

void loop() {
  testButtons();
}

(totally untested)

1 Like

That's indeed a good start. thx for making this clear.
( Bad luk i'm no programmer, it is difficult for me to think about sequences and possibilities....)
I start with your advice!
Bye.

Dear J-M-L , this is a really great start and you got the goal of the game correct. When they make a wrong combination a voice let them know, and then they are asked to start again ( reset the program )
Thx a lot !

let us know how you progress. we'll help along the way if you struggle.

Hi there. The part to read the buttons and light the corresponding led works fine in my test build ( only 5 buttons at this time.) But I don't understand how to check the winning combination from const byte (solutions) to be true or not. I understand how to check 1 variable, but not a combination of 3.

in the code above I added how to do it - probably after you copied it. The idea is to maintain a small array with the selected button for each column and compare that array with the accepted solutions. if you have a match, it's a win.

          // check if there is a winning combination
          for (byte i = 0; i < solutionsCount; i++) {
            if (memcmp(currentAnwer, solutions[i], colCount) == 0) {
              win();
              return;
            }
          }

fully untested though

I was indeed to eager to wait for your complete code. :slight_smile:
I check this out tomorrow!
Thx a lot. really !

hope it works and children can have fun again ! :slight_smile:

Works like a charm ! Now I'm waiting for a sound module to implement audio and a lot of pushbuttons! :grinning: Sadly the very last electronics shop in the area has closed.... so it's waiting for DHL !

have fun. Season's greetings!!

al the same for you ! And again, thank you a lot.

The "Sparkfun" module seems to be the Geetech version ( very old stuff??? )
Its the geeetech VS1053 mp3 shield.
I tried already a lot of libraries, downloaded tons of GIthub stuff, but I don't succeed in reading the SD card. Always errors reading the card. Tried the original libraries, the mpflaga github version, changed SD cards, formatted them .... nothing....

I simply don't get it working... :frowning:

Hi - what are you trying to achieve?

just to play some mp3's ( vocal messages, and an applause when the answer is correct ).

I manage to see the files on the SD card, but I can't get it to play. Memory adress errors, error code 2, 6, 7 ( depending on the library I try ).
Github is not very clear for an amateur like me. :roll_eyes:
My first experiments were on the UNO to learn the concept, but I will retry on the Mega, the board i wil use in the end. if I have some more consistant data, I will post it.
Greetings !

do you have a link to your module?

https://www.geeetech.com/wiki/index.php/Arduino_MP3_shield_board_with_TF_card