#include <U8g2lib.h>
const unsigned char outline [] PROGMEM = {
0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0C, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xF8, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03,
};
static const unsigned char battery [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f, 0x02, 0x20, 0xfa, 0xaf, 0xfa, 0xaf,
0xfa, 0xaf, 0xfa, 0x2f, 0x02, 0x20, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char dashboard [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f, 0xf8, 0x1f, 0xfc, 0x3f, 0xfe, 0x7f,
0xf8, 0x1f, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x78, 0x1e, 0x00, 0x00, 0x00, 0x00
};
const unsigned char settings [] PROGMEM = {
0x00, 0x00, 0x80, 0x01, 0xc8, 0x13, 0xfc, 0x3f, 0xf8, 0x1f, 0xf8, 0x1f, 0x3c, 0x3c, 0x3e, 0x7c,
0x3e, 0x7c, 0x3c, 0x3c, 0xf8, 0x1f, 0xf8, 0x1f, 0xfc, 0x3f, 0xc8, 0x13, 0x80, 0x01, 0x00, 0x00
};
const unsigned char poweroff [] PROGMEM = {
0x00, 0x00, 0x20, 0x04, 0x08, 0x10, 0x24, 0x24, 0x10, 0x08, 0x0a, 0x50, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0a, 0x50, 0x10, 0x08, 0x24, 0x24, 0x08, 0x10, 0x20, 0x04, 0x00, 0x00
};
const unsigned char nowifi [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xf8, 0x1f, 0x1c, 0x38, 0x04, 0x20, 0xe0, 0x07,
0x70, 0x06, 0x00, 0x1c, 0xc0, 0x3d, 0xc0, 0x37, 0x00, 0x3c, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00
};
const unsigned char wifion [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x0f, 0xfc, 0x3f, 0x3e, 0x7c, 0x8e, 0x71, 0xf0, 0x0f,
0xf8, 0x1f, 0x30, 0x0c, 0x80, 0x01, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define battery_width 16
#define battery_height 16
// Button pin definitions
#define enterbtn 18
#define upbtn 5
#define downbtn 17
// Menu variables
int currentMenu = 0;
const char* menuItems[] = {"Home", "Settings", "Power Off"};
const unsigned char* menuIcons[] = {dashboard, settings, poweroff};
const int menuCount = sizeof(menuItems) / sizeof(menuItems[0]);
// Initialize the display
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
void drawMenu() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.drawStr(4, 11, "AttendScan");
u8g2.drawStr(72, 11, "70%");
u8g2.drawXBMP(93, 0, battery_width, battery_height, nowifi);
u8g2.drawXBMP(112, 0, battery_width, battery_height, battery);
u8g2.setFont(u8g_font_7x14);
u8g2.drawStr(25, 37, menuItems[currentMenu]);
u8g2.drawXBMP(4, 24, 16, 16, menuIcons[currentMenu]);
u8g2.drawXBMP(0, 22, 128, 21, outline);
int nextMenu = currentMenu + 1;
if (nextMenu >= menuCount) {
nextMenu = 0;
}
u8g2.drawStr(25, 59, menuItems[nextMenu]);
u8g2.drawXBMP(4, 46, 16, 16, menuIcons[nextMenu]);
u8g2.sendBuffer();
}
// Setup function to initialize the display and show initial messages
void setup() {
Serial.begin(9600);
pinMode(enterbtn, INPUT_PULLUP);
pinMode(upbtn, INPUT_PULLUP);
pinMode(downbtn, INPUT_PULLUP);
u8g2.begin();
Serial.print("Connecting to WiFi");
delay(100);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.drawStr(4, 11, "AttendScan");
u8g2.drawStr(72, 11, "70%");
u8g2.drawXBMP(93, 0, battery_width, battery_height, nowifi);
u8g2.drawXBMP(112, 0, battery_width, battery_height, battery);
u8g2.setFont(u8g_font_7x14B);
u8g2.drawStr(4, 37, "Wifi Connecting.......");
u8g2.sendBuffer();
u8g2.clearBuffer();
u8g2.drawStr(4, 37, "Wifi Connected");
u8g2.sendBuffer();
delay(2000);
u8g2.drawXBMP(93, 0, battery_width, battery_height, wifion);
}
// Loop function to handle button presses and update the display
void loop() {
bool menuChanged = false;
// Check if the up button is pressed
if (digitalRead(upbtn) == LOW) {
currentMenu--;
if (currentMenu < 0) {
currentMenu = menuCount - 1;
}
delay(200);
menuChanged = true;
}
// Check if the down button is pressed
if (digitalRead(downbtn) == LOW) {
currentMenu++;
if (currentMenu >= menuCount) {
currentMenu = 0;
}
delay(200);
menuChanged = true;
}
drawMenu();
}