create menu

Hi everyone. I am thinking about creating a menu system for my Arduino project. I'd like to display a menu that basically says press m to do whatever, f to do something else, etc. I'm not sure I'm making myself clear, but I'm using the serial port to allow someone to input a command. If I put the menu system in the loop, I obviously get it reprinted over and over. Any thoughts on how to correct this?

Many thanks, Symir

Not clear what you mean by "printed over and over" - could you post what you've got, and maybe we can make suggestions?

I don't have any code to show. I'm just in the thinking process. Basically, I'd like to just display a set of options to the user, like this:

To use the program press: a: do 1st item b: do 2nd item c: etc.

I can do this in C easily because it's not inside a loop, but here it would be in the main loop and would display continuously. Does this help?

You could still easily add a blocking loop in the code, ie (rusty C code ahead!):

while (!digitalRead(pin)) {/*wait*/}

where "pin" is a pin a button is connected to or whatnot, waiting for input (a HIGH value, button on pin is pressed).

But this is wasteful of the processor (especially if there are other things to do). It would be better to let the loop run, and then use checks and states (ie, a state machine) to change what is going on based on what is pressed and in what order. This way, you aren't blocking the loop with a "do nothing" loop.

Does this make sense?


I think he wanted to use the Serial port as the control via a pc or something.

So instead of readDigital(), use Serial.available

void setup(){  // draw menu first here

void loop(){

 if (Serial.available()) {
  //read char
  doMenu(char);  //process menu inputs
  //draw menu again


   Serial.println(" a) help.");

doMenu(char c){
  switch c:
     case 'a':
        //do a

Theres got to be about a million examples of this out there, did you try Google?