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?
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.
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
drawMenu();
}
void loop(){
if (Serial.available()) {
//read char
doMenu(char); //process menu inputs
//draw menu again
drawMenu();
}
}
drawMenu(){
Serial.println(" a) help.");
}
doMenu(char c){
switch c:
case 'a':
//do a
break;
etc....
Theres got to be about a million examples of this out there, did you try Google?