ILI9225 scroll down menu

Hi everyone,

I'm in need of some assistance.
I'm using a ILI9225 tfd screen.

I need to have a scroll menu control by three pushbutton up, down and select.
when one of the item is selected a different screen should appear to do a different task.

this is what I have so far. and it's not working
the library for TFT_22_ILI9225 has limited functions.

thanks in advance.

void loop{
    char *menuEntries[]={ "ITEM_1",
        "ITEM_2", "ITEM_3", "ITEM_4"};
    switch (menuState) {
  
    // Display and interogate the menu
        case -1:
            menu.entries = 4;
            displayMenu(menuEntries);
            menuState = updateMenu(menuEntries);
            break;
    
    // Display ITEM 1        
        case 0:
            displayITEM_1();
            menuState = -1;
            break;
            
    // Display ITEM 2
        case 1:
            displayITEM_2();
            menuState = -1;
            break;

            // Display ITEM 3
        case 2:
            displayITEM_3();
            menuState = -1;
            break;

            // Display ITEM 4
        case 3:
            displayITEM_4();
            menuState = -1;
            break;
           
            
            while (1==1) {}
    }
    // Delay and wait for a button...log observations while waiting
    if (menuState != -1) {  
        waitForButton();
    }
}

/*****************************************************************************/
// ***************************************************************************
// MENU
// ***************************************************************************
/*****************************************************************************/

// Display the menu
/*****************************************************************************/
void displayMenu(char *menuEntries[]) {
    tft.setFont(Terminal6x8); 
  for (int i=0; i<menu.entries; i++) {
      tft.setCursor(0, i * 30 + 10);
    if (i == menu.selected) {
      tft.fillRect(0, i * 30 + 10, 160, 25, COLOR_WHITE);
    }
    else {
      tft.setTextColor(COLOR_RED);
      tft.drawRectangle(0, i * 30 + 10, 160, 25, COLOR_WHITE);
    }
    int yOffset = (12 - String(menuEntries[i]).length()) * 7 + 5;
      tft.setCursor(yOffset, i * 30 + 15);
      tft.println(menuEntries[i]);
  }
}

// Update the menu based on button pushes
/*****************************************************************************/
int updateMenu(char *menuEntries[]) {
  while (1==1) {
    int selected = menu.selected;
    int pushed = waitForButton();
    if (pushed == 2) {
      return(menu.selected);
    }
    if (pushed == 1) {
      if (selected < menu.entries - 1) {
        selected++;
      }
      else {
        selected = 0;
      }
    }
    if (pushed == 3) {
      if (selected > 0) {
        selected--;         
      }
      else {
        selected = menu.entries - 1;
      }
    }
    if (selected != menu.selected) {
      menu.selected = selected;
      displayMenu(menuEntries);
    }
  }
}

First off. Your "code" does not compile.

You can always describe your project with a flowchart drawn in pencil
or a list of numbered steps written in English.

All that I have is a JPEG. So I have written an example:

#include "SPI.h"
#include "TFT_22_ILI9225.h"

#define TFT_RST A4 //8
#define TFT_RS  A3 //9
#define TFT_CS  A5 //10  // SS
#define TFT_SDI A2 //11  // MOSI
#define TFT_CLK A1 //13  // SCK
#define TFT_LED A0 //3   // 0 if wired to +5V directly

// Use hardware SPI (faster - on Uno: 13-SCK, 12-MISO, 11-MOSI)
//TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED);
// Use software SPI (slower)
TFT_22_ILI9225 tft(TFT_RST, TFT_RS, TFT_CS, TFT_SDI, TFT_CLK, TFT_LED);

int count_1 = 0, selected = -1;
const int UP_BTN = 6, DOWN_BTN = 7, SELECT_BTN = 5;

void setup()
{
    char *menuEntries[] = { "item1",
                            "item2", "item3", "item4", "TOTAL",
                          };
    Serial.begin(9600);
    Serial.println("Hello jaflue");
    pinMode(UP_BTN, INPUT_PULLUP);
    pinMode(DOWN_BTN, INPUT_PULLUP);
    pinMode(SELECT_BTN, INPUT_PULLUP);
    tft.begin();
    tft.setOrientation(1);
    int wid = tft.maxX(), ht = tft.maxY();
    int x = 0, y = ht - 1 - 28 * 5;
    tft.fillRectangle(0, 0, wid - 1, y, COLOR_WHITE);
    tft.setFont(Terminal6x8);
    tft.drawText(5, 20, "Click MENU to ADD+ or SUBTRACT-", COLOR_WHITE);
    tft.setFont(Terminal12x16);
    tft.drawText(50, 0, "Main Menu", COLOR_WHITE);
    for (int i = 0; i < 5; i++, y += 28) {
        tft.drawRectangle(0, y, 85, y + 28, COLOR_WHITE);
        tft.drawRectangle(85, y, wid - 1, y + 28, COLOR_WHITE);
        tft.drawText(5, y + 7, menuEntries[i], COLOR_WHITE);
        tft.drawText(87, y + 7, "$", COLOR_WHITE);
    }
    delay(1000);
}

void loop(void)
{
    static int count_old = -1, selected_old = -1;  //illegal value
    int y;
    if (digitalRead(UP_BTN) == LOW) {
        if (count_1 < 3) count_1++;
    }
    else if (digitalRead(DOWN_BTN) == LOW) {
        if (count_1 > 0) count_1--;
    }
    else if (digitalRead(SELECT_BTN) == LOW) {
        selected = count_1;
    }
    if (count_1 != count_old) { //changed value
        if (count_old < 0) count_old = 0;
        y = 35 + 28 * count_old;
        tft.drawRectangle(0, y, 85, y + 28, COLOR_WHITE);
        y = 35 + 28 * count_1;
        tft.drawRectangle(0, y, 85, y + 28, COLOR_RED);
        count_old = count_1;
    }
    if (selected != selected_old) { //changed value
        if (selected_old < 0) selected_old = 0;
        y = 35 + 28 * selected_old;
        tft.drawText(87, y + 7, "$          ", COLOR_WHITE);
        y = 35 + 28 * count_1;
        tft.drawText(87, y + 7, "selected", COLOR_WHITE);
        selected_old = count_1;
    }
    delay(50);
}

Note that I have just guessed at your screen positioning. Hence the magic numbers.

In a real program, I would have a menuDraw() function and menuUpdate() function with parameters and return values.

David.

thanks,

I appreciated it