// https://forum.arduino.cc/t/the-if-statement-dose-not-work-after-the-recursion/1015359
#include <Streaming.h> // some library for printing out like c++
const long BAUD = 9600;
const int DELAY = 200 ;
void switchPress(int SwitchNum);
void setup() {
pinMode(6, INPUT); // Switch G-LED
Serial.begin(BAUD);
while (!Serial){
// wait for serial port to connect.
}
}
void loop() {
Serial << (digitalRead(6) == HIGH) << endl; // to Check out the result of the logic expression
// before go to the if statement
if(digitalRead(6) == HIGH){ // my problem in this IF
while(digitalRead(6) == HIGH){
continue;
}
Serial << "the program pass the if statement .... " << endl; // the program pass this line
// when start again using recursion
// but at the first time it dose not !!!
// the same problem with the IF
while(true){
delay(DELAY);
if(digitalRead(6) == HIGH){
switchPress(6);
}
Serial.println("I am stuck here.");
}
}
}
void switchPress(int SwitchNum){
while(digitalRead(SwitchNum) == HIGH){
continue; // just to make sure the problem not from the switch and it is LOW !!!
}
if(digitalRead(SwitchNum) == LOW){ // to check again it is LOW
Serial << "THE PROGRAM GOING TO START AGAIN" << endl;
loop();
}
}