thanks for replying.
this code is meant to be a game for disabled kids (we are building a special press button for them)
any way, this is a simple press button that lite up leds one by one, and also allow to reset the game.
I know my code is written badly, I did try and make is as easy to follow as possible.
Thanks
Angel
//****************************************************************************//
//****************************************************************************//
/*
decide which PIN is for a LED
and which PIN in ment for a button
*/
const int buttonPin =9; // the number of the pushbutton pin
const int led1 = 1; // the number of the LED pin
const int led2 = 2; // the number of the LED pin
const int led3 = 3; // the number of the LED pin
const int led4 = 4; // the number of the LED pin
const int buz = 5; // the number of the buzzer pin
const int res = 0; // the number of the reset
/*
control the time for the BLINK
*/
const int delayCountDown = 500; //delay countdown
const int delayblink = 200; //delay for blink
//****************************************************************************//
//****************************************************************************//
//set values
const int deleyRICHOD = 10; //delay for switcing
int buttonState; // variable for reading the pushbutton status
int counter = 0; //main counter
int firstTime = 1; //flag
int resetState; // variable for reading reset status
int flagReset = 0;
// actual program beggins
void loop(){
if (firstTime == 1){
countDown();
firstTime=0;
}//if
//check for reset
resetState = digitalRead(res);
if (resetState == LOW){
// should be resetBoard() but I just want to see that it will actually work
countDown();
}
//was a button pressed ?
buttonState = digitalRead(buttonPin);
if(buttonState == LOW){
counter++;
if(counter == 0)
zero();
if(counter == 1)
one();
if(counter == 2)
two();
if(counter == 3)
three();
if(counter == 4){
four();
counter = 0;
victory();
}//(counter == 4)
checkButtonReleae();
}//(buttonState == LOW)
} //loop
void setup() {
// initialize the LED pin as an output:
pinMode(buttonPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(buz, OUTPUT);
pinMode(res, INPUT);
}
void zero(){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
} //zero
void one(){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
} //one
void two(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
} //two
void three(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
} //three
void four(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
} //four
void five(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
} //five
void six(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
} //six
void full(){
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
} //full
void victory(){
digitalWrite(buz, HIGH);
for (int i=0; i<4; i++){
delay(delayblink);
zero();
delay(delayblink);
full();
}//for
delay(delayblink);
zero();
digitalWrite(buz, LOW);
}//victory
void checkButtonReleae(){
delay(deleyRICHOD);
while( digitalRead(buttonPin) == LOW){
}//while
delay(deleyRICHOD);
}
void countDown(){
digitalWrite(buz, LOW);
four();
delay(delayCountDown);
three();
delay(delayCountDown);
two();
delay(delayCountDown);
one();
delay(delayCountDown);
zero();
delay(delayCountDown);
}//countDown
void resetBoard(){
digitalWrite(buz, LOW);
flagReset = 0;
counter = 0;
countDown();
} // resetBoard