Kind of a 'Whack a Mole' game

Hi guys,

i'm trying to make kind of a whack a mole game but i'm a bit stuck right now..

I'm using this code:

const int row[9] = { 0,1,2 }; // positive pin
const int col[9] = { 3,4,5}; // negative pin
int n = 100;
int pixels[3][3]; //the matrix

void setup(){
  
  for (int thisPin = 0; thisPin < 3; thisPin++){
   //initialize the output pins
   pinMode(col[thisPin], OUTPUT);
   pinMode(row[thisPin], OUTPUT);
   // thake the col pins high to ensure that the LED's are off
   digitalWrite(col[thisPin], HIGH);
  }
 }


void loop(){
  int Tmatrix[3][18] = {
    { 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0},
    { 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0},
    { 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1}
  };
 
  int anim = 0; //begin van de teller
  int n = 500; //duur aanstaan
  
  while(1){
    //while (x>0){
      //x--;
      for(int  C = 0; C<3; C++){
        for(int L = 0; L<3; L++){
          if(Tmatrix[L][C+anim] == 1){
            digitalWrite(row[L], HIGH);
            digitalWrite(col[C], LOW);
            delay(n);
          }
          digitalWrite(row[L], LOW);
          digitalWrite(col[C], HIGH);
          delay(n);
        }
      }
      delay(500); //tijd tussen knipperen
    anim++;
    if (anim == 18) anim=0; // na alle 
    //}
  }
  delay(5000);
}

This is originally a code for a segment display and what it does now is flashing led's according the Tmatrix. (from left to right).

I've got a multiplexed raster above these led's (3 x 3 wires) and when you push this it connects 2 wires.

My goal is to make a game that has 9 random (or semi random, following a pattern) flashing led's and when a led is lid and you push it, it will remain that state.
So eventually the whole board is lid up. (the person who has a full lid up board first wins.)

The anode en cathode of the Led's are connected to pins [ 0 - 5] and the 'touch'grid is connected to pins [ A0 - A5 ]
The grid of the wires is structured like this:
which i got from : http://www.instructables.com/id/Arduino-and-Touchpad-Tic-Tac-Toe/

I'm trying to find a way to make the led stay high when you push it (and when it is lid up) has anyone some good ideas? Would be great! :slight_smile:

Grumpy_Mike developed a clever LED illuminated button a while back for one of his projects, details can be found here:
http://www.thebox.myzen.co.uk/Hardware/Mini_Monome.html

Hey... did you ever get your whack-a-mole game working?

I just came up with the same idea. Thinking I might just design it from the ground up.

Brammes:
I'm trying to find a way to make the led stay high when you push it (and when it is lid up) has anyone some good ideas? Would be great! :slight_smile:

Separate the led wiring from the button wiring at least half way.
The leds should run on abstraction of button data (logical state gotten from hardware states over time) rather than physical contact closures (hardware states).

Debounce the buttons. (logical state from hardware state over time)

Button code and led code should be separated except for variables to pass information like what button has changed and what led(s) to light or turn off.

Any code to turn button information into commands for leds (logical code) should be separate from the code for the buttons and leds (hardware code).