the serial monitor is not waiting for the second input after taking the first input. why?
I am attaching my code here please let me know.
int A;
int B;
int ans;
int act;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
Serial.begin(9600);
Serial.println("enter your first number");
while (Serial.available()==0){
}
A=Serial.parseInt();
Serial.println("enter your second number");
while (Serial.available()==0){
}
B=Serial.parseInt();
Serial.println("select action you want");
Serial.println(" 1 Add, 2 sub,");
while (Serial.available()==0){
int A;
int B;
int P;
int ans;
int act;
void setup() {
Serial.begin(115200);
}
void loop() {
Serial.println("enter your first number");
while (Serial.available()==0){}
A=Serial.parseInt();Serial.print(" reçu ");Serial.println(A);
while (Serial.available()!=0){P=Serial.parseInt(); }
Serial.println("enter your second number");
while (Serial.available()==0){}
B=Serial.parseInt();Serial.print(" reçu ");Serial.println(B);
while (Serial.available()!=0){P=Serial.parseInt(); }
Serial.println("select action you want");
Serial.println(" 1 Add, 2 sub,");
while (Serial.available()==0){}
act=Serial.parseInt();
while (Serial.available()!=0){P=Serial.parseInt(); }
if (act==1){ans = A+B;}
if (act==2){ans =A-B;}
Serial.println(ans);
}
il y a surement plus "élégant",
tu teste si le tampon n'est pas vide, pour savoir si quelque chose arrive
comme tu ne lis pas la totalité du tampon,
l'instruction d'attente si vide est fausse et le programme continue
il faut vider le tampon de la liaison serie