#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
// ' icon_nong', 16x16px
const unsigned char epd_bitmap__icon_nong[] PROGMEM = {
0x00, 0x00, 0x3f, 0xfc, 0x40, 0x02, 0x5f, 0xfa, 0x50, 0x0a, 0x53, 0xca, 0x54, 0x2a, 0x55, 0xaa,
0x55, 0xaa, 0x54, 0x2a, 0x53, 0xca, 0x50, 0x0a, 0x5f, 0xfa, 0x40, 0x02, 0x3f, 0xfc, 0x00, 0x00};
// ' icon_us', 16x16px
const unsigned char epd_bitmap__icon_us[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x60, 0x0e, 0x70, 0x1e, 0x78, 0x3e, 0x7c, 0x7e, 0x7e, 0x7e,
0x7f, 0x00, 0x7f, 0x80, 0x3f, 0xc0, 0x1f, 0xe0, 0x0f, 0xe0, 0x07, 0xe0, 0x00, 0x00, 0x00, 0x00};
// ' icon_sumi', 16x16px
const unsigned char epd_bitmap__icon_sumi[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3f, 0xc4, 0x44, 0x44, 0x48, 0x84,
0x48, 0x84, 0x48, 0x84, 0x48, 0x84, 0x48, 0x84, 0x48, 0x84, 0x7f, 0xfc, 0x00, 0x00, 0x00, 0x00};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 144)
const unsigned char *bitmap_icons[3] = {
epd_bitmap__icon_nong,
epd_bitmap__icon_sumi,
epd_bitmap__icon_us};
// ' selected_box', 128x21px
const unsigned char epd_bitmap__selected_box[] PROGMEM = {
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80};
// ' scroll_bar', 8x64px
const unsigned char epd_bitmap__scroll_bar[] PROGMEM = {
0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02,
0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00};
// ' scroller', 8x64px
const unsigned char epd_bitmap__scroller[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x05, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#define BUTTON_NEXT_PIN 8 // pin for next button
#define BUTTON_SELECT_PIN 9 // pin for select button
#define BUTTON_PREVIOUS_PIN 10 // pin for previous button
const int NUM_ITEMS = 3; // number of icons you have
int button_next_clicked;
int button_select_clicked;
int button_previous_clicked;
int item_selected = 0; // Which item in the menu is selected
int item_sel_previous; // previous item - item before the selected one
int item_sel_next; // next item - item after the selected one
char menu_items[NUM_ITEMS][20] = {
{"Nong"},
{"Sumi"},
{"Us"}};
int scroller_pos = 4;
void setup()
{
// Define pins for buttons
// INPUT_PULLUP means the button is HIGH when not pressed, and LOW when pressed
// since it's connected between some pin and GND
pinMode(BUTTON_NEXT_PIN, INPUT_PULLUP);
pinMode(BUTTON_SELECT_PIN, INPUT_PULLUP);
pinMode(BUTTON_PREVIOUS_PIN, INPUT_PULLUP);
}
void loop()
{
if ((digitalRead(BUTTON_NEXT_PIN) == LOW) && (button_next_clicked == 0))
{
item_selected = item_selected + 1;
button_next_clicked = 1;
scroller_pos += 22;
if (item_selected >= NUM_ITEMS)
{
item_selected = 0;
scroller_pos = 4;
}
}
else if ((digitalRead(BUTTON_PREVIOUS_PIN) == LOW) && (button_previous_clicked == 0))
{
item_selected = item_selected - 1;
button_previous_clicked = 1;
scroller_pos -= 22;
if (item_selected < 0)
{
item_selected = NUM_ITEMS - 1;
scroller_pos = 48;
}
}
if ((digitalRead(BUTTON_NEXT_PIN) == HIGH) && (button_next_clicked == 1))
{
button_next_clicked = 0;
}
if ((digitalRead(BUTTON_PREVIOUS_PIN) == HIGH) && (button_previous_clicked == 1))
{
button_previous_clicked = 0;
}
int item_sel_previous = item_selected - 1;
if (item_sel_previous < 0)
{
item_sel_previous = NUM_ITEMS - 1;
}
item_sel_next = item_selected + 1;
if (item_sel_next >= NUM_ITEMS)
{
item_sel_next = 0;
}
u8g.firstPage();
do
{
// previous item
u8g.setFont(u8g_font_7x14);
u8g.drawStr(23, 15, menu_items[item_sel_previous]);
u8g.drawBitmapP(4, 2, 16 / 8, 16, bitmap_icons[item_sel_previous]);
// selected item
u8g.setFont(u8g_font_7x14B);
u8g.drawStr(23, 37, menu_items[item_selected]);
u8g.drawBitmapP(4, 24, 16 / 8, 16, bitmap_icons[item_selected]);
// next item
u8g.setFont(u8g_font_7x14);
u8g.drawStr(23, 59, menu_items[item_sel_next]);
u8g.drawBitmapP(4, 46, 16 / 8, 16, bitmap_icons[item_sel_next]);
u8g.drawBox(125, scroller_pos, 3, 12);
u8g.drawBitmapP(120, 0, 8 / 8, 64, epd_bitmap__scroll_bar);
u8g.drawBitmapP(0, 22, 128 / 8, 21, epd_bitmap__selected_box);
} while (u8g.nextPage());
}