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);
}
}
}