![Image](http://forums.4fips.com/2016/4fips.com_arduino_interactive_menu_over_serial_sample.gif)
The example below shows how to approach this:
Code: Select all
// [CODE BY FIPS @ 4FIPS.COM, (c) 2016 FILIP STOKLAS, MIT-LICENSED]
#define RST "\033[0m"
#define SEL "\033[1;93;41m"
static int sel = 0;
void refresh() {
Serial.print("\033[2J"); // clear screen
Serial.print("\033[H"); // cursor to home
Serial.print(sel == 0 ? SEL : RST);
Serial.println(" Menu Item 1 ");
Serial.print(sel == 1 ? SEL : RST);
Serial.println(" Menu Item 2 ");
Serial.print(sel == 2 ? SEL : RST);
Serial.println(" Menu Item 3 ");
Serial.print(RST);
}
void setup() {
Serial.begin(9600);
while (!Serial) delay(100);
refresh();
}
void loop() {
if (Serial.available()) {
switch (Serial.read()) {
case '[': {
sel = sel <= 0 ? 0 : (sel - 1);
break;
}
case ']': {
sel = sel >= 2 ? 2 : (sel + 1);
break;
}
}
refresh();
}
}