Before we go any further I am a beginner and still finding my feet.
Below is the code i have written to create a simple menu in the serial monitor where i want the user to make choices etc.
Firstly, the int's at the beginning...is this the best way to go when creating a menu or should i be using #define. As i'm a beginner i'm not even sure if this is te correct thing to do.
Secondly, now that i have printed all the text i need to, to the serial monitor, how do i write an if statement in the void loop that takes the user input from the serial monitor and takes them to where they want to be. How could i test this is working? Logically if they select option one I want to perhaps print something in the serial monitor to confirm they are where they want to be. I will get onto the actual conversions later.
I hope that makes sense.
Many thanks.
int menuoption1 = 1;
int menuoption2 = 2;
int menuoption3 = 3;
int menuoption4 = 4;
int menuoption5 = 5;
int menuoption6 = 6;
int menuoption7 = 7;
int menuoption8 = 8;
int menuoption9 = 9;
int menuoption10 = 10;
int menuoption11 = 11;
int menuoption12 = 12;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
// prints text and menu options for user to select from
Serial.println("Welcome to my Bin, Dec, Oct, Hex Converter");
delay(2000);
Serial.println(" ");
Serial.println("Please select a number from the options available");
delay(2000);
Serial.println(" ");
Serial.println("Main Menu");
Serial.println("---------");
delay(1000);
Serial.println("1. 2's comp Binary to Hex,");
delay(1000);
Serial.println("2. 2's comp Binary to Octal,");
delay(1000);
Serial.println("3. 2's comp Binary to Decimal,");
delay(1000);
Serial.println("4. Octal to 2's comp Binary,");
delay(1000);
Serial.println("5. Octal to Hex,");
delay(1000);
Serial.println("6. Octal to Decimal,");
delay(1000);
Serial.println("7. Hex to 2's comp Binary,");
delay(1000);
Serial.println("8. Hex to Octal,");
delay(1000);
Serial.println("9. Hex to Decimal,");
delay(1000);
Serial.println("10. Decimal to 2's comp Binary,");
delay(1000);
Serial.println("11. Decimal to Hex,");
delay(1000);
Serial.println("12. Decimal to Octal.");
}
void loop() {
}
int menuselect;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
// prints text and menu options for user to select from
Serial.println(F("Welcome to my Bin, Dec, Oct, Hex Converter"));
delay(1000);
Serial.println(F(" "));
Serial.println(F("Please select a number from the options available"));
Serial.println(F(" "));
Serial.println(F("Main Menu"));
Serial.println(F("---------"));
Serial.println(F("1. 2's comp Binary to Hex,"));
Serial.println(F("2. 2's comp Binary to Octal,"));
Serial.println(F("3. 2's comp Binary to Decimal,"));
Serial.println(F("4. Octal to 2's comp Binary,"));
Serial.println(F("5. Octal to Hex,"));
Serial.println(F("6. Octal to Decimal,"));
Serial.println(F("7. Hex to 2's comp Binary,"));
Serial.println(F("8. Hex to Octal,"));
Serial.println(F("9. Hex to Decimal,"));
Serial.println(F("10. Decimal to 2's comp Binary,"));
Serial.println(F("11. Decimal to Hex,"));
Serial.println(F("12. Decimal to Octal."));
}
void loop()
{
char ch;
if (Serial.available()) //Constantly checks to see if anything has been sent over the USB Connection and if it needs to be processed
{
menuselect = Serial.read(); //Reads a single letter
if (menuselect = '1')
{
Serial.flush();//Try to clear the serial monitor and then go to conversion
delay(1000);
Serial.println("2's comp Binary to Hex");
}}}
I havent tested this yet, but if a user selects an option from the menu, i then need to clear the serial monitor and make it look to the user they are in that option. How do I do that?
If you're using the serial monitor from IDE, you can't, but you could use a terminal emulator like PuTTY, and use a VT52 (or similar) clear screen escape sequence to do all kinds of fancy stuff.
kopite:
Below is the code i have written to create a simple menu in the serial monitor where i want the user to make choices etc.
If you like, take a look at the attached ZIP file. It's the source code from a project I recently did. It's a valve controller that has a lot of menu items and selections. You may get some ideas from it.