Interactive menu code little problem

hey im new in arduino and igot this menu code, everything is working fine until im trying to enter the second option in the menu (it does nothing)
the display is connected as it should and also all the wiring...

any suggestions?

#include "U8glib.h"
#include <U8glib.h>

U8GLIB_KS0108_128 u8g(45, 43, 41, 39, 37, 35, 33, 31, 47, 53, 51, 49, 0); // 8Bit Com: D0..D7: 8,9,10,11,4,5,6,7 en=18, cs1=14, cs2=15,di=17,rw=16
#define KEY_NONE 0
#define KEY_PREV 1
#define KEY_NEXT 2
#define KEY_SELECT 3
#define KEY_BACK 4

// DOGS102 shield configuration values
//uint8_t uiKeyPrev = 2;
//uint8_t uiKeyNext = 4;
//uint8_t uiKeySelect = 5;
//uint8_t uiKeyBack = 3;

// DOGM128-Shield configuration values
// DOGXL60-Shield configuration values
uint8_t uiKeyPrev = 22;
uint8_t uiKeyNext = 24;
uint8_t uiKeySelect = 26;
uint8_t uiKeyBack = 28;

uint8_t uiKeyCodeFirst = KEY_NONE;
uint8_t uiKeyCodeSecond = KEY_NONE;
uint8_t uiKeyCode = KEY_NONE;

//VOLTAGE
float value1 = 0;

float EREZ1 = 1;

void uiSetup(void) {
// configure input keys

pinMode(uiKeyPrev, 22); // set pin to input
digitalWrite(uiKeyPrev, HIGH); // turn on pullup resistors
pinMode(uiKeyNext, 24); // set pin to input
digitalWrite(uiKeyNext, HIGH); // turn on pullup resistors
pinMode(uiKeySelect, 26); // set pin to input
digitalWrite(uiKeySelect, HIGH); // turn on pullup resistors
pinMode(uiKeyBack, 28); // set pin to input
digitalWrite(uiKeyBack, HIGH); // turn on pullup resistors
}

void uiStep(void) {
uiKeyCodeSecond = uiKeyCodeFirst;
if ( digitalRead(uiKeyPrev) == LOW )
uiKeyCodeFirst = KEY_PREV;
else if ( digitalRead(uiKeyNext) == LOW )
uiKeyCodeFirst = KEY_NEXT;
else if ( digitalRead(uiKeySelect) == LOW )
uiKeyCodeFirst = KEY_SELECT;
else if ( digitalRead(uiKeyBack) == LOW )
uiKeyCodeFirst = KEY_BACK;
else
uiKeyCodeFirst = KEY_NONE;

if ( uiKeyCodeSecond == uiKeyCodeFirst )
uiKeyCode = uiKeyCodeFirst;
else
uiKeyCode = KEY_NONE;
}

#define MENU_ITEMS 4
char *menu_strings[MENU_ITEMS] = { " EREZ1", " EREZ2", " TEMP", " DAVID" };

uint8_t menu_current = 0;
uint8_t menu_redraw_required = 0;
uint8_t last_key_code = KEY_NONE;
uint8_t menu_previous = 0;

void drawMenu(void) {
uint8_t i, h;
u8g_uint_t w, d;

u8g.setFont(u8g_font_6x13);
u8g.setFontRefHeightText();
u8g.setFontPosTop();

h = u8g.getFontAscent()-u8g.getFontDescent();
w = u8g.getWidth();
for( i = 0; i < MENU_ITEMS; i++ ) {
d = (w-u8g.getStrWidth(menu_strings[i]))/2;
u8g.setDefaultForegroundColor();
if ( i == menu_current ) {
u8g.drawBox(0, ih+1, w, h);
u8g.setDefaultBackgroundColor();
}
u8g.drawStr(d, i
h, menu_strings[i]);
}

}

void updateMenu(void) {
if ( uiKeyCode != KEY_NONE && last_key_code == uiKeyCode ) {
return;
}
last_key_code = uiKeyCode;

switch ( uiKeyCode ) {
case KEY_NEXT:
menu_current++;
if ( menu_current >= MENU_ITEMS )
menu_current = 0;
menu_redraw_required = 1;
break;
case KEY_PREV:
if ( menu_current == 0 )
menu_current = MENU_ITEMS;
menu_current--;
menu_redraw_required = 1;
break;
case KEY_SELECT:
//EREZ1
if (menu_current == 0 && digitalRead(uiKeySelect) == LOW) {
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr(10, 20, "EREZ1!");

    } while (u8g.nextPage());
    
  }
  break;

  //EREZ2
  if (menu_current == 1 && digitalRead(uiKeySelect) == LOW) {
    u8g.firstPage();
    do {
      u8g.setFont(u8g_font_6x10);
      u8g.drawStr(10, 20, "EREZ2!");
     
    
    } while (u8g.nextPage());
    
  }
  break;
  


case KEY_BACK:
  menu_current = menu_previous;
  menu_redraw_required = 1;
  break;

}
}

void setup() {

uiSetup(); // setup key detection and debounce algorithm
menu_redraw_required = 1; // force initial redraw
}

void loop() {

uiStep(); // check for key press

if ( menu_redraw_required != 0 ) {
u8g.firstPage();
do {
drawMenu();
} while( u8g.nextPage() );
menu_redraw_required = 0;

}

updateMenu(); // update menu bar

}

//EREZ2
if (menu_current == 1 && digitalRead(uiKeySelect) == LOW) {
u8g.firstPage();
do {
u8g.setFont(u8g_font_6x10);
u8g.drawStr(10, 20, "EREZ2!");

    } while (u8g.nextPage());
    
  }
  break;
   this is the section that is not working

thx for everyone that helpes!

Hello, help us help you... do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

1 Like

The following code will NEVER get executed:

      //EREZ2
      if (menu_current == 1 && digitalRead(uiKeySelect) == LOW) {
        u8g.firstPage();
        do {
          u8g.setFont(u8g_font_6x10);
          u8g.drawStr(10, 20, "EREZ2!");
        } while (u8g.nextPage());
      }
      break;

It is preceded by a break statement.

thank you that was the problem <3

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.