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! ![]()