Oled Menu with U8g2 lib

Hi everyone,
i would like to create a menu, like the 3d printer menu, on a Oled.
I use the U8g2lib because it looks very complete and easy.

The idea is this:

  • menu1
  • function1()
  • menu2
  • function2()
  • menu3
  • menu3.1
  • menu3.2
  • function3()

Seeing the doc and i founded some interesting commands, like:

So i wrote some code to use it:

U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);

const char *string_list =
        "NFC\n"
        "RFID\n"
        "Cirrocumulus\n"
        "Cirrostratus";


uint8_t current_selection = 0;

void draw_NFC(){
        u8g2.drawStr(15,15,"NFC");
        delay(2000);
        //u8g2.clearDisplay();
}

void draw_RFID(){
        u8g2.drawStr(15,15,"RFID");
        delay(2000);
        //u8g2.clearDisplay();
}

void setup() {
        Serial.begin(9600);
        u8g2.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8); // Arduboy 10 (Production)

        u8g2.setFont(u8g2_font_6x12_tr);

        u8g2.drawStr(0,15,"GO");
        delay(2000);
        //u8g2.clearDisplay();
}

void loop() {
                u8g2.setFont(u8g2_font_ncenB14_tr);
                u8g2.drawStr(0,15,"Hello World!");

                current_selection = u8g2.userInterfaceSelectionList(
                        "Tags",
                        current_selection,
                        string_list);

                Serial.println(current_selection);

                if ( current_selection == 0 ) { // home/cancel button
                        //
                }
                if (current_selection == 1) { // NFC
                        draw_NFC();
                }
                if (current_selection == 2) { // RFID
                        draw_RFID();
                }
                if (current_selection == 3) { // other menu
                         const char *string_list =
                               "A\n"
                               "B\n"
                               "C";
                          if ( current_selection == 0 ) { // home/cancel button
                                //
                          }
                          if (current_selection == 1) { // NFC
                               draw_NFC();
                          }
                //else draw_error();

               delay(1000);
}

That easy code should do:

  • print userInterfaceSelectionList ( done )
  • when i selected a name in the list, start the function/other menu ( not works )

Somebody can help to understand what does not works?

Hi, how did you solve this problem? THanks.