im trying to get out of Do loop by using break but it doesnt work
any ideas ?
void Drive3(){
if(digitalRead(Present3) == HIGH ){//&& (Door_sensor) == HIGH)){
do{
digitalWrite(Up_relay, HIGH);
digitalWrite(Button_led, LOW);
digitalWrite(Cab_lamp, HIGH);
if(DoorStatus == 0) break;
}
while(digitalRead(Present3) == HIGH ) ;
digitalWrite(Up_relay, LOW);
Active = 0;
CabStatus = 3;
CabLampOff();
if(CabRequest < 9) CabRequest = 9;
}
I don't see where you have printed the value of DoorStatus before you test it. Isn't that part of the debugging process you should be following?
Paul
Nothing wrong with the snippet afaics, you might try posting your whole sketch.
Where is the value of DoorStatus changed in order to cause the do/while loop to break ?
here is the main loop which check the door status
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(Door_sensor) == LOW){//Door Open
if(digitalRead(Present0) == LOW) CabStatus = 0;
if(digitalRead(Present1) == LOW) CabStatus = 1;
if(digitalRead(Present2) == LOW) CabStatus = 2;
if(digitalRead(Present3) == LOW) CabStatus = 3;
if(digitalRead(Request0) == HIGH) CabRequest = 0;
if(digitalRead(Request1) == HIGH) CabRequest = 1;
if(digitalRead(Request2) == HIGH) CabRequest = 2;
if(digitalRead(Request3) == HIGH) CabRequest = 3;
digitalWrite(Button_led, LOW);
digitalWrite(Cab_lamp, HIGH);
Active = 0;
DoorStatus = 0;
PORTC = B00011000;
}
Any chance you can post the whole program all in one place and all at one time? That makes it a lot easier (and less annoying) for people to debug rather than the snippets you keep posting.
How does changing DoorStatus in the loop() function affect DoorStatus in the do/while loop in the Drive3() function ?
Perhaps if we see your whole program it will become clear
its Done thx guys
i have tried this before but it didnt work & now its ok
void Drive3(){
if(digitalRead(Present3) == HIGH ){
do{
digitalWrite(Up_relay, HIGH);
digitalWrite(Button_led, LOW);
digitalWrite(Cab_lamp, HIGH);
if(digitalRead(Door_sensor) == LOW)break;
}
while(digitalRead(Present3) == HIGH ) ;
digitalWrite(Up_relay, LOW);
Active = 0;
CabStatus = 3;
CabLampOff();
if(CabRequest < 9) CabRequest = 9;
}
}