5

I have a list of set-ups and I only have 2 rows in the lcd , I'm trying to scroll down for the moment and I'm doing this by changing the row in the setcursor function to either 0 or 1.

However since that I'll be having about 10 set-ups I used an equation that will change the rows to 0 and one for the ones I want to display and a negative number for those that I don't want to appear. The problem is when setting the cursor's row to -1 or 2, it will ignore the one with row one (which is the 2nd row).

Is there a way that I can overcome this problem ? by setting it to a row that will not appear on my LCD? I'm using #include <LiquidCrystal.h> and I already set lcd.begin(16, 2);

int  colom[5] = {
    0-goDown,1-goDown,2-goDown,3-goDown,4-goDown  };
for (int i = 0; i < 4; i++) {
    if (colom[i] > 1) colom[i] = -1;
}

  lcd.setCursor(0, colom[0]);
  lcd.print("choise 1 ");
  lcd.setCursor(0, colom[1]);
  lcd.print("choise 2 ");
  lcd.setCursor(0, colom[2]);
  lcd.print("choise 3 ");
  lcd.setCursor(0, colom[3]);
  lcd.print("choise 4 ");
  lcd.setCursor(0, colom[4]);
  lcd.print("choise 5 ");

So here goDown is 0 so choice 1 and 2 should appear, but I'm only getting choice 1 and in the second row it's changing quickly between 2 and 5, it's not constant.

I thought about doing an if condition for each choice but that will be a lot of code to write and it won't be efficient for my application.

  • 1
    What is the LCD library you're using? – jfpoilpret Mar 20 '14 at 0:11
  • #include <LiquidCrystal.h> – user730 Mar 20 '14 at 0:35
  • Please edit your question to include a Minimal, Complete, and Verifiable example of code, not just snippets. Minimal means you've stripped away irrelevant stuff, just leaving what's needed to show the problem. Complete means all the library names are shown, all the variable declarations, and all the function definitions – so people don't have to waste time guessing what you did or what you meant. Verifiable means it can be compiled and tested, allowing other people to test their theories about the problem – user31481 Nov 23 '17 at 21:36
4

This is a bad strategy in general. You should not be issuing print calls for things you don't want to print and relying on the lcd library to filter for you because they're out of bounds.

Call print for only the choices you want to display.

char* menu[] = {
    "choice 1",
    "choice 2",
    "choice 3",
    "choice 4",
    "choice 5",
};
const int numMenuItems = sizeof menu / sizeof *menu;
const int numLcdRows = 2;


// start out at the top of the menu
int scrollPos = 0;

void drawMenu() {
    for (int i=0; i < numLcdRows; ++i) {
        lcd.setCursor(0, i); 
        lcd.print(menu[i + scrollPos]);
    }
}

To scroll up or down, just adjust the scroll offset:

inline void scrollUp() {
    if (scrollPos > 0)
        scrollPos--;
}

inline void scrollDown() {
    if (scrollPos < numMenuItems - numLcdRows)
        scrollPos++;
}

Note this is untested code written for a library I've never seen (just inferring how it works from your post); it's for illustration purposes only.

| improve this answer | |
1

I have written some abstraction code for handling LCD menus, located here: https://github.com/red-green/Arduino_Mobile_OS

Here is the main snippet:

byte menu(String title,const String* strings,byte length) {
  boolean select, esc; static byte item, selection;
  select = false;
  esc = false;
  item = 1;
  lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(title);
    lcd.print(": ");
    lcd.print(item);
    lcd.setCursor(0,1);
    lcd.print(strings[item]);
    delay(100);

  while (!select) {
    uint8_t buttons = lcd.readButtons();
    if (buttons) {
    if (buttons & BUTTON_UP) {
      item--; 
    }
    if (buttons & BUTTON_DOWN) {
      item++;
    }
    if (buttons & BUTTON_LEFT) {
      esc = true;
    }  
    if (buttons & BUTTON_SELECT) {
      selection = item;
      select = true;
    }

    item = constrain(item,1,length - 1);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(title);
    lcd.print(": ");
    lcd.print(item);
    lcd.setCursor(0,1);
    lcd.print(strings[item]);
    if (esc) {
      select = true;
      selection = 0;
    }
    delay(100);

  }
  } 
  return(selection);
}

You may need to change the button handling to work with your setup. To call, have an array of items before setup, like this:

const String utilmenuitems[6] = {"back","Random Numbers","Uptime","Device Info"};

You can then call it like:

byte return = menu("Utilities",utilmenuitems,4);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.