Hi all,
I am sorry for this simple question. I am still learning Arduino code.
Currently I am doing this following code; to read input from user for the char of m (which refer to minute) or s (second).
Serial.println("Is it in min or sec? (m/s)");
while (Serial.available() == 0);
{
char i = Serial.parseFloat();
if (i = 'm')
{
Serial.print("ts = ");
Serial.print(h, DEC); //h refers to the input int written by user previously
Serial.println(" min");
}
else if (i = 's')
{
Serial.print("ts = ");
Serial.print(h, DEC);
Serial.println(" sec");
}
else
{
Serial.println("Error!!");
}
}
When I run the code, and click serial monitor, here is the result:
- if user enters 'm', it will display min.
- if user enters 's', it will still display min.
- if user enters other than m/s, it still displaying min.
but what I want the code to do is
- whenever user enters 'm' it will show min
- whenever user enters 's' it will show sec
- whenever user enters other characters beside 'm' or 's', the error warning will display and the code will ask again the user to input m/s.
Thank you in advance for your help and kindness.