I'm trying to build a test program for some hardware. Basically I want to select the piece of hardware with the outer switch case then select the test with the inner switch case. I'm trying to accomplish this by using serial input in the Arduino IDE monitor.
I can't make it work whatever I do. I either end up stuck in the outer switch case or I never enter the inner switch case where I want to select the test.
I've got a bit of code below:
char select_addon;
char select_test;
void setup() {
Serial.begin(9600);
Serial.println("(1) PB1");
Serial.println("(2) PB2");
Serial.println("(3) PB3");
}
void loop() {
if (Serial.available() > 0) {
select_addon = Serial.read();
switch (select_addon) {
case '1':
Serial.println("Test");
if (Serial.available() > 0 ) {
select_test = Serial.read();
switch (select_test) {
case '4':
Serial.println(" Test 1.1");
break;
case '5':
Serial.println(" Test 1.2");
break;
case '6':
Serial.println(" Test 1.3");
break;
}
}
break;
case '2':
Serial.println("TEST 2");
break;
case '3':
Serial.println("TEST 3");
break;
}
}
}
Obviously this isn't the finished code, but it's the switch case structure I've been trying to implement. Any suggestions on how I can enter the inner switch case?
int select_addon = String(Serial.read()).toInt()
; andcase 3
, insteadcase '3'
– dandavis May 31 '17 at 19:22