not reading button press

the variables red blue green and yellow are led ports. bred bblue bgreen byellow are button ports. we are trying to make a simple game of simon. google flash simon to see the game. our problem is that Arduino keeps saying that all the buttons are pressed and that variable bpress which is supposed to show which button is pressed keeps outputting four.

plz help

int red = 13;
int blue = 12;
int green = 11;
int yellow = 10;
int bred = 4;
int bblue = 3;
int bgreen = 2;
int byellow = 1;
int brd = 0;
int bbd = 0;
int bgd = 0;
int byd = 0;
boolean newgame;
int patt [10];
int level;
int i;
boolean show;
int bpress;
int seq;

void setup()
{
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(yellow, OUTPUT);

pinMode(bred, INPUT);
pinMode(bblue, INPUT);
pinMode(bgreen, INPUT);
pinMode(byellow, INPUT);
show = false;
newgame = true;
}

void loop(){
if (newgame == true)
{
randomSeed(analogRead(0));
for(i=0;i < 9; i++)
{

patt = random(1,4);

  • }*
  • for(i=0;i<4;i++)*
  • {*
  • digitalWrite(red,HIGH);*
  • digitalWrite(blue,HIGH);*
  • digitalWrite(green,HIGH);*
  • digitalWrite(yellow,HIGH);*
  • delay(500);*
  • digitalWrite(red,LOW);*
  • digitalWrite(blue,LOW);*
  • digitalWrite(green,LOW);*
  • digitalWrite(yellow,LOW);*
  • delay(500); *
  • }*
    level = 2;
    show = true;
    newgame = false;
    }
    if(show == true){
  • for(i=0;i<level;i++)*
  • {*
    _ if(patt == 1){ digitalWrite(red,HIGH); delay(1000); digitalWrite(red,LOW); delay(200); }_
    _ if(patt == 2){ digitalWrite(blue,HIGH); delay(1000); digitalWrite(blue,LOW); delay(200); }
    if(patt == 3){ digitalWrite(green,HIGH); delay(1000); digitalWrite(green,LOW); delay(200); }
    if(patt == 4){ digitalWrite(yellow,HIGH); delay(1000); digitalWrite(yellow,LOW); delay(200); }
    * }
    seq = 1;
    show = false;
    } *_

if((show == false) && (newgame == false) && (seq <= level))
{
* brd = digitalRead(bred);*
* bbd = digitalRead(bblue);*
* bgd = digitalRead(bgreen);*
* byd = digitalRead(byellow);*
* bpress = 0;*
* if(brd == HIGH) { bpress = 1; }*
* if(bbd == HIGH) { bpress = 2; }*
* if(bgd == HIGH) { bpress = 3; }*
* if(byd == HIGH) { bpress = 4; }*
* Serial.println(bpress);*
* if((patt[seq - 1] != bpress) && (bpress > 0)){ newgame = true; }*

}
}

If your buttons are wired like the button tutorial http://www.arduino.cc/en/Tutorial/Button then digitalRead will read high when the buttons are not pressed. If this is how you wired them you can change your code as follows: if(brd == LOW) { bpress = 1; }

also, your yellow button is on a pin used by the arduino serial port, try it connected to pin 5.

Good luck and have fun!