Hello,
I am asking for some help with the serial monitor on how I can make the monitor wait until a user inputs a value before it continues on through the loop. It's the part in the code where I am trying to get a value for long amt; in the switch case. The while loop with Serial.available does stop, but only for second then continues on through the rest of the loop.
void loop(){
char decision = Serial.read();
switch(decision){
case '1':
long amt = 0;
Serial.println("In milliliters, how much gas would you like to capture? Enter below.");
while (Serial.available()) {
amt = Serial.parseInt();
break;
}
O2Collection(electrodes,pump,amt);
Serial.println("Oxygen collection finished. Would you like to do anything else?");
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
break;
}
Serial.println("didnt work");
}
void O2Collection(int electrodes, int pump, long amt){
tim = millis();
Serial.println("Oxygen Collection Initiated. Type 'stop' to quit if necessary.");
digitalWrite(electrodes, HIGH);
digitalWrite(pump, HIGH);
while(millis()<amt){
if(Serial.readStringUntil('\n') == "stop"){
goto finish;
}
}
finish:
digitalWrite(pump, LOW);
digitalWrite(electrodes, LOW);
}