This Program do not fuction good and I have no idea why?
const int Switch1 = 3; //Switch 1 is connected to Arduino's pin 3.
const int Switch2 = 4; //Switch 2 is connected to Arduino's pin 4.
const int Switch3 = 5; //Switch 3 is connected to Arduino's pin 5.
const int Switch4 = 6; //Switch 4 is connected to Arduino's pin 6.
const int start = 7; //Start botton is connected to Arduino's pin 7.
const int pass = 8; //Pass input signal is connected to Arduino's pin 8.
const int pass_led = 9; //Pass led is connected to Arduino's pin 9.
const int fail = 10; //Fail input signal isC connected to Arduino's pin 10.
const int fail_led = 11; //fail led is connected to Arduino's pin 11.
int i,j,k; //General variables for loops.
void setup()
{
pinMode(Switch1, OUTPUT);
pinMode(Switch2, OUTPUT);
pinMode(Switch3, OUTPUT);
pinMode(Switch4, OUTPUT);
pinMode(start, INPUT);
pinMode(pass, INPUT);
pinMode(pass_led, OUTPUT);
pinMode(fail, INPUT);
pinMode(fail_led, OUTPUT);
}
void loop()
{
if (digitalRead (start) == HIGH) // If start button is pressed, 1st sequence stars.
i=10;
j=10;
k=10;
{
digitalWrite(Switch1, HIGH);
digitalWrite(Switch2, HIGH);
digitalWrite(Switch3, HIGH);
digitalWrite(Switch4, HIGH);
delay(1000);
for (i=10; i>=10; i++)//Wait for the pass or fail signal for the 1st sequence
{
if(fail==HIGH)//Breaks the 1st sequence loop and turns on fail led if 1st test fails.
{
digitalWrite(fail_led, HIGH);
break;
}
}
}
if(digitalRead (pass)==HIGH)//Starts the 2nd sequence if the 1st test is passed.
{
digitalWrite(pass_led, HIGH);//Pass_led is turned on to indicate that the 1st test is passed.
digitalWrite(Switch1, HIGH);//2nd sequence stars.
digitalWrite(Switch2, HIGH);
digitalWrite(Switch3, LOW);
digitalWrite(Switch4, LOW);
delay(1000);
digitalWrite(pass_led, LOW);
for (j=10; j>=10; j++)//Wait for the pass or fail signal for the 2nd sequence.
{
if( digitalRead (fail)==HIGH)//Breaks the 2nd sequence loop and turns on fail led if 2nd test fails.
{
digitalWrite(fail_led, HIGH);
break;
}
}
}
if(digitalRead (pass)==HIGH)
{
digitalWrite(pass_led, HIGH);
digitalWrite(Switch1, LOW);//Starts the 3rd sequence if the 2nd test is passed.
digitalWrite(Switch2, LOW);
digitalWrite(Switch3, LOW);
digitalWrite(Switch4, HIGH);
delay(1000);
digitalWrite(pass_led, LOW);
for (k=10; k>=10; k++) //Wait for the pass or fail signal for the 3rd sequence.
{
if(digitalRead (fail)==HIGH)//Breaks the 3rd sequence loop and turns on fail led if 3rd test fails.
{
digitalWrite(fail_led, HIGH);
break;
}
if(digitalRead (pass)==HIGH)
{
digitalWrite(pass_led, HIGH);
break;
}
}
}
}