I am trying to create a program that does a sequence of events. Using the example code below: if two crtierias are filled, print Step 1, then I want it to print Step 2 only when digitalRead(5)==LOW. When I opened the serial monitor, it would printed "Step 1", "waiting for LS" a couple of times and then execute code back at the start of the void loop ();
General coding question: 5 lines down, I executed a function. When the program gets there, does it exit the void loop(), finish the function, and then resume the next line in void loop()?
I copied a slice of my code below.
//more void loop code
if ((pipeSSelection==1) && (uSonar==1)){//reading ultrasonic sensor
Serial.print("Step 1");
enterLA(13); //Linear actuator Enters
while (digitalRead(5)==HIGH){ //reading the limit switch
Serial.print("waiting for LS");
}
if (digitalRead(5)==LOW){ //Limit switch detects pipe
Serial.print("Step 2");
while (digitalRead(5)==HIGH){ //reading the limit switch
Serial.print("waiting for LS");
}
if (digitalRead(5)==LOW){ //Limit switch detects pipe
Serial.print("Step 2");
The while loop
won't end until the pin
goes LOW. It really seems
pointless to ask, then,
"is the pin really LOW?",
don't you
think?
Wouldn't it have been nice if my question had been easy to read? Your code isn't. Use Tools + Auto Format before posting ALL of your code.
General coding question: 5 lines down, I executed a function. When the program gets there, does it exit the void loop(), finish the function, and then resume the next line in void loop