Pages: [1]   Go Down
Author Topic: Serial Monitor Menu  (Read 712 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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.

Code:
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() {
   
}
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bump
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.println("1. 2's comp Binary to Hex,");
This is quite wasteful of precious RAM.
Better would be:
Code:
Serial.println(F("1. 2's comp Binary to Hex,"));
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Tasmania - Australia
Online Online
Sr. Member
****
Karma: 10
Posts: 299
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  delay(1000);
This is wasteful of precious TIME
Better would be
Code:

 smiley-twist
Logged


0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For user input, read up on Serial.available() and Serial.read().

-br
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for pointing these issues out. Excuse my ignorance but what is the 'F' in your Serial.println bit of code? Basically why does that save RAM?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The "F" macro puts your strings in flash memory, and more importantly, keeps them there.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As simple as that. Thanks.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Below is refreshed code.

Code:
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?

Thanks in advance.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24430
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i then need to clear the serial monitor
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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok. I will read up on this.

Thanks again.
Logged

Tasmania - Australia
Online Online
Sr. Member
****
Karma: 10
Posts: 299
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but you could use a terminal emulator like PuTTY, and use a VT52

Gosh that reminds me so much of things back in the '80's, using VT52 terminals from DEC.

Paul
Logged


Worst state in America
Offline Offline
God Member
*****
Karma: 24
Posts: 672
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Hope this helps you.

* valve_control.zip (6.76 KB - downloaded 7 times.)
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Brilliant thanks.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ive just used the switch case for the users input and that works fine thanks.
Logged

Pages: [1]   Go Up
Jump to: