// Stepper motor on Wokwi!
/*
Console Menu example for Arduino
Read data coming from console using the Serial.parseInt() function
and use for option select.
Created 13 Jun 2018
By Cenek Havelka
For www.utfg.info
*/
int receivedInt; //prepare variable for input
void setup() {
Serial.begin(9600); //setup console
//Print main menu
Serial.println("<MAIN MENU>");
Serial.println("------------------------");
Serial.println("1.)OPTION 1");
Serial.println("2.)OPTION 2");
Serial.println("3.)OPTION 3");
Serial.println("4.)OPTION 4");
Serial.println("------------------------");
}
void loop() {
recvInt(); //call function to read value from console
PrintByInput(); //call function with SWITCH
}
void recvInt() {
while(Serial.available() == 0) { } //wait for input from console
receivedInt = Serial.parseInt(); // parse input to INT, other values are ignored
}
void PrintByInput() {
if (receivedInt != NULL) { //call SWITCH if input is available
switch (receivedInt) { //print by input, otheway say !WRONG INPUT!
case 1:
Serial.print("OPTION-");
Serial.println(receivedInt);
break;
case 2:
Serial.print("OPTION-");
Serial.println(receivedInt);
break;
case 3:
Serial.print("OPTION-");
Serial.println(receivedInt);
break;
case 4:
Serial.print("OPTION-");
Serial.println(receivedInt);
break;
default:
Serial.println("!WRONG INPUT!");
break;
}
receivedInt = NULL;
}
}