Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15514

How to scroll down/up a menu on a ST7920 128x64 LCD display ?

$
0
0

Hi,

I'm working on developing a menu and I reached the part where I want to scroll down/up the menu but I don't know how.

This is the code I'm working on:

#include <U8g2lib.h>
// constants ////////////////////////////////////////////////
// # lists settings

#define   LIST_COUNT            8
#define   LIST_PER_FRAME        5

#define   LIST_Y_START_POINT    1
#define   LIST_X_START_POINT    2
#define   LIST_Y(_Y)            (LIST_Y_START_POINT+(12*_Y))

// # selection settings
#define   SELECT_WIDTH          65
#define   SELECT_HEIGHT         11
#define   SELECT_X_START_POINT  0
#define   SELECT_Y_START_POINT  0
#define   SELECT_Y(_Y)          (SELECT_Y_START_POINT+(12*_Y))

// variables ////////////////////////////////////////////////
uint8_t select_ptr = 0;
//uint8_t list_y = LIST_Y(0);

struct example_list{
  uint8_t y_position;
  const char* list_name;
};

example_list list1[] = {
  {LIST_Y(0), "SETTING 1"},
  {LIST_Y(1), "SETTING 2"},
  {LIST_Y(2), "SETTING 3"},
  {LIST_Y(3), "SETTING 4"},  
  {LIST_Y(4), "SETTING 5"},
  {LIST_Y(5), "SETTING 6"},
  {LIST_Y(6), "SETTING 7"},
  {LIST_Y(7), "SETTING 8"}, 
};

U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8);

void u8g2_prepare(void) {
  u8g2.setFont(u8g2_font_6x10_tf);
  u8g2.setFontRefHeightExtendedText();
  u8g2.setDrawColor(1);
  u8g2.setFontPosTop();
  u8g2.setFontDirection(0);
}

void glcd_initialize(void) {
  u8g2.begin(); 
  u8g2_prepare();
}

void glcd_print_list(void){

  u8g2.firstPage();
  do {

    // draw list
    u8g2.setDrawColor(1);
    for(int i = 0; i < LIST_COUNT; i++){
      u8g2.drawStr(LIST_X_START_POINT, list1[i].y_position, list1[i].list_name);
    }

    // selected list
    u8g2.setDrawColor(1);
    u8g2.drawBox(SELECT_X_START_POINT, SELECT_Y(select_ptr), SELECT_WIDTH, SELECT_HEIGHT);
    u8g2.setDrawColor(0);
    u8g2.drawStr(LIST_X_START_POINT, list1[select_ptr].y_position, list1[select_ptr].list_name);

    if(select_ptr > 5){
      // u8g2.drawRFrame(u8g2,,,,); // <---------- I'm here
    }
    
  } while (u8g2.nextPage());   
}

As select_ptr will be modified by push button read function.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15514