I'm using a CyberCortex AV that has LEDs from 32 to 35 and buttons from 40 to 43. I want to make a simple game - press the button while the other player is pressing - if you do, you win. However, what I actually get is that LEDs 1 to 3 are on, and pressing left button causes led 1 to go off. I'm not sure why, and I've re-written the code, but it still has the same behaviour.
int firstWas = -1;
void setup() {
pinMode(32, OUTPUT);
pinMode(35, OUTPUT);
pinMode(40, INPUT);
pinMode(43, INPUT);
resetLights();
}
void loop() {
checkForInputs();
}
void checkForInputs(){
boolean leftDown = false;
boolean rightDown = false;
if(digitalRead(40)){
leftDown = true;
if(firstWas == -1){
firstWas = 0;
}
}
if(digitalRead(43)){
rightDown = true;
if(firstWas == -1){
firstWas = 1;
}
}
if(leftDown && rightDown){
if(firstWas == 0){
gameOver(1);
} else {
gameOver(0);
}
firstWas = -1;
}
}
void gameOver(int who){
if(who == 0){
digitalWrite(35, HIGH);
delay(600);
} else {
digitalWrite(32, HIGH);
delay(600);
}
resetLights();
}
void resetLights(){
digitalWrite(32, LOW);
digitalWrite(35, LOW);
}
Thanks