[SOLVED] Scrolling menu w/ LCD Shield / buttons

I'm working on building an HVAC thermostat and I am using the Adafruit RGB LCD Shield w/ 5 buttons.

This is my code for the project (too long to post here)

With the code as is, the menu (Starting at line 169) is either at position 0 or 1, here or there, AC or HEAT adjustment, so to speak. I want to add some other things to the menu, such as FAN control. Therefore I need a third menu item. I'm not sure how to handle the programming for this.

Any pointers or ideas or other projects that already do this that I can learn from would be greatly appreciated. Thanks in advance!

Just did a search on "Arduino LCD Menu" and turned up loads of useful results e.g

http://playground.arduino.cc/Code/Menu

I think that adding one item to the menu:

char* menu[] = {"Cooling", "Heating", "Fan"}; // Menu display for either setting the high point or the low point of the temp range

, and changing a bit this code:

// If the Left Button is pushed, change the menu context
if (buttons & BUTTON_LEFT) {
  if (menuPosition == 1) {
    menuPosition = 0;
  } else {
    menuPosition = 1;
  }
}

// If the Right Button is pushed, change the menu context
if (buttons & BUTTON_RIGHT) {
  if (menuPosition == 1) {
    menuPosition = 0;
  } else {
    menuPosition = 1;
  }
}

you can do it.

EDIT: You need to consider that you have 3 options and not only 2. I don't know if you know what I'm talking about.

luisilva:
EDIT: You need to consider that you have 3 options and not only 2. I don't know if you know what I'm talking about.

I do and that is kind of where my mind was at. I just didn't know if there was a better/smoother way to do it than a bunch of if/then statements.

But I suppose, in pseudo, that it's "if position 1, go to 2. if position 2, go to 3" etc.

If I was in your place, I will do it like this:

// If the Left Button is pushed, change the menu context
if (buttons & BUTTON_LEFT) {
  menuPosition--;  // decrement the variable
  if ( menuPosition < 0 ) {
    menuPosition = 0;          // don't let it decrement too mush 
  }
}

// If the Right Button is pushed, change the menu context
if (buttons & BUTTON_RIGHT) {
  menuPosition++;  // increment the variable
  if ( menuPosition <= 2 ) {
    menuPosition = 2;          // don't let it increment too mush 
  }
}

In this way, you travel to one side of the menu by pressing the LEFT button and to the other side by pressing the RIGHT button.

See, that's why I come here! I like that answer. Thanks friend!

Note that you need to change other things like:

if (buttons & BUTTON_UP) {
  if (menuPosition == 0) {
    coolModifier = 1;
  }
  if (menuPosition == 1) {
    heatModifier = 1;
  }
}

and this:

if (menuPosition == 0) {
  lcd.print(cool);
}
if (menuPosition == 1) {
  lcd.print(heat);
}

and other, I only point you the “travel” in the options, the others things is up to you.

You can try to use switch/case now that you have more than 2 options.

Good luck.

PS: If you think that the topic is closed, please rename the subject of the first post to “[SOLVED]…”, and give user that help you a “+Karma”.

Edit. Didn't see your second post with example code. I will work on it. I gave you karma!

Here's a fun little problem I get with that code.

code

My fault, sorry about that.

In this line (215):

 if ( menuPosition <= 2 ) {

change to:

 if ( menuPosition >= 2 ) {

The symptoms of the video is that you are trying to write something that is outside the array (so the garbage in the screen). So when the menuPosition is ‘3’ it still ‘3’ (as you don’t execute the if statment) and as your array menu only have the elements 0, 1 and 2, when you try to write the element 3… BOOOM!

:grin:

Yep! I found it right as you replied. Seems to be working now. I am certain I can take it the rest of the way!

Let me tell you: very nice work!