#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
// ' resistor_block', 16x16px
const unsigned char epd_bitmap__resistor_block [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x7c, 0x3e, 0x83, 0xc1, 0x10, 0x08, 0x3b, 0x5c, 0x3d, 0xac, 0xfd, 0xaf,
0x3d, 0xac, 0x3b, 0x5c, 0x10, 0x08, 0x83, 0xc1, 0x7c, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// ' breaker_rating_icon', 16x16px
const unsigned char epd_bitmap__breaker_rating_icon [] PROGMEM = {
0x00, 0x00, 0x0f, 0xf0, 0x0f, 0xf0, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c,
0x3c, 0x3c, 0x3f, 0xfc, 0x3f, 0xfc, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x00, 0x00
};
// ' breaker_type_icon', 16x16px
const unsigned char epd_bitmap__breaker_type_icon [] PROGMEM = {
0x0f, 0xf0, 0x08, 0x10, 0x09, 0x90, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x0b, 0xd0, 0x09, 0x90,
0x09, 0x90, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x08, 0x10, 0x09, 0x90, 0x08, 0x10, 0x0f, 0xf0
};
// ' cable_size_icon', 16x16px
const unsigned char epd_bitmap__cable_size_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x10, 0x02, 0x10, 0x31, 0x20, 0x09, 0x40,
0x05, 0x40, 0x05, 0x40, 0x05, 0x40, 0x0a, 0xa0, 0x08, 0xa0, 0x08, 0xa0, 0x0a, 0xa0, 0x0a, 0xa0
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 192)
const unsigned char* bitmap_icons[4] = {
epd_bitmap__breaker_rating_icon,
epd_bitmap__breaker_type_icon,
epd_bitmap__cable_size_icon,
epd_bitmap__resistor_block
};
// ' scrollbar_background', 8x64px
const unsigned char epd_bitmap__scrollbar_background [] 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
};
// ' selected_outline', 128x21px
const unsigned char epd_bitmap__selected_outline [] PROGMEM = {
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0
};
#define BUTTON_UP_PIN 4 //pin for up button
#define BUTTON_ENTER_PIN 8 //pin for enter button
#define BUTTON_DOWN_PIN 12 //pin for down button
const int NUM_ITEMS = 4;
char menu_items[NUM_ITEMS] [20] = {
{"Breaker Rating"},
{"Breaker Type"},
{"Cable Size"},
{"Resistor Block"}
};
int item_selected = 0; //which item is selected
int item_sel_previous = 0; //which item is previous
int item_sel_next = 0; // which item is next
int current_screen =0; //0=menu, 1=selection screen
int button_up_clicked = 0; // only perform action when button is clicked, and wait until another press
int button_enter_clicked = 0; // same as above
int button_down_clicked = 0; // same as above
void setup() {
pinMode(BUTTON_UP_PIN, INPUT_PULLUP);
pinMode(BUTTON_ENTER_PIN, INPUT_PULLUP);
pinMode(BUTTON_DOWN_PIN, INPUT_PULLUP);
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop() {
if ((digitalRead(BUTTON_UP_PIN) == LOW) && (button_up_clicked == 0)) {//UP button is pressed
item_selected = item_selected - 1;
button_up_clicked = 1;
if(item_selected <0) {
item_selected = NUM_ITEMS - 1;
}
}
if ((digitalRead(BUTTON_DOWN_PIN) == LOW) && (button_down_clicked == 0)) {//DOWN button is pressed
item_selected = item_selected + 1;
button_down_clicked = 1;
if(item_selected >= NUM_ITEMS) {
item_selected = 0;
}
}
if ((digitalRead(BUTTON_UP_PIN) == HIGH) && (button_up_clicked == 1)) { // unclick
button_up_clicked = 0;
}
if ((digitalRead(BUTTON_DOWN_PIN) == HIGH) && (button_down_clicked == 1)) { // unclick
button_down_clicked = 0;
}
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(22, 16, menu_items[item_sel_previous]);
u8g.drawBitmapP(3,2,16/8,16, bitmap_icons[item_sel_previous]);
// selected item
u8g.setFont(u8g_font_7x14B);
u8g.drawStr(22, 37, menu_items[item_selected]);
u8g.drawBitmapP(3,24,16/8,16, bitmap_icons[item_selected]);
// next item
u8g.setFont(u8g_font_7x14);
u8g.drawStr(22, 58, menu_items[item_sel_next]);
u8g.drawBitmapP(4,46,16/8,16, bitmap_icons[item_sel_next]);
u8g.drawBitmapP(0,22,128/8,21, epd_bitmap__selected_outline);
u8g.drawBitmapP(120,0,8/8,64, epd_bitmap__scrollbar_background);
u8g.drawBox(125, 64/NUM_ITEMS * item_selected, 3, 64/NUM_ITEMS);
} while (u8g.nextPage());
}