Hi, I'm trying to build a menu switch case where I can choose different options using serial monitor. But, it works only for once. When I try to enter the submenu, it doesn't work.
void setup() {
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0);
{
int data = Serial.read();
switch (data)
{
case 'A':
Serial.print("Select drawer:\n1\n2\n3\n4\n5");
if (Serial.available() > 0);
{
int data2 = Serial.read();
while (Serial.available() > 0) {
Serial.read();
switch (data2)
{
case 'B':
Serial.print("1st drawer");
}
}
}
}
}
}
Hi,
Think about how long it takes for your finger to move from the first key press to the second key. Now think about how long it takes from reading the first byte in the serial buffer to checking to see if there is another byte waiting to be read.
The semicolons after your 'if' statements are causing the code blocks in the braces {} following it, to do nothing. So, the 'if' statements never change anything, and the code in the blocks is always executed.
PerryBebbington:
Hi,
Think about how long it takes for your finger to move from the first key press to the second key. Now think about how long it takes from reading the first byte in the serial buffer to checking to see if there is another byte waiting to be read.
The semicolons after your 'if' statements are causing the code blocks in the braces {} following it, to do nothing. So, the 'if' statements never change anything, and the code in the blocks is always executed.
I removed the semi-colon after the if statements but it's still not working.