#include "bitmap.h"
#include <Wire.h>
#include <U8g2lib.h>
#define OLED_ADDR 0x3C
int menuindex = 0;
const int sw_pin[] = {2,12,13,14.4};
const int bitmap_allArray_LEN = 14;
const unsigned char* bitmap_allArray[14] = {
bitmap_battery_0,
bitmap_battery_100,
bitmap_battery_25,
bitmap_battery_50,
bitmap_battery_75,
bitmap_battery_alert,
bitmap_battery_charge,
bitmap_battery_disconnedted,
bitmap_session_disconnected,
bitmap_session_connected,
bitmap_wifi_100,
bitmap_wifi_25,
bitmap_wifi_50,
bitmap_wifi_75
};
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, 22, 21, /* reset=*/ U8X8_PIN_NONE);
// ----------------------------------------------------------------
// ---------------------------- Void ------------------------------
// ----------------------------------------------------------------
bool getSw(char swChar) {
switch(swChar) {
case 'L':
if (digitalRead(sw_pin[2]) == LOW) {return true;} else {return false;};
break;
case 'R':
if (digitalRead(sw_pin[4]) == LOW) {return true;} else {return false;};
break;
case 'U':
if (digitalRead(sw_pin[3]) == LOW) {return true;} else {return false;};
break;
case 'D':
if (digitalRead(sw_pin[0]) == LOW) {return true;} else {return false;};
break;
case 'E':
if (digitalRead(sw_pin[1]) == LOW) {return true;} else {return false;};
break;
default:
return false;
}
}
/*
// Funkcja wyświetlająca menu
void displayMenu(int currentMenuItem) {
u8g2.firstPage();
do {
u8g2.setFont(u8g2_font_6x10_tf);
u8g2.setCursor(0, 10);
u8g2.print("Menu:");
u8g2.setCursor(0, 20);
if (currentMenuItem == 0) {
u8g2.drawBox(0, 19, 10, 10);
}
u8g2.print("Opcja 1");
u8g2.setCursor(0, 35);
if (currentMenuItem == 1) {
u8g2.drawBox(0, 34, 10, 10);
}
u8g2.print("Opcja 2");
u8g2.setCursor(0, 50);
if (currentMenuItem == 2) {
u8g2.drawBox(0, 49, 10, 10);
}
u8g2.print("Opcja 3");
} while (u8g2.nextPage());
}
*/
// ----------------------------------------------------------------
// ---------------------------- Setup -----------------------------
// ----------------------------------------------------------------
void setup()
{
Serial.begin(115200);
/*
// initialize the OLED object
if(!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("[FAIL] Coudn't initialize OLED diplay"));
for(;;);
}
*/
u8g2.begin();
u8g2.enableUTF8Print();
u8g2.setFont(u8g2_font_helvR08_tf);
u8g2.setDrawColor(1);
u8g2.setFontMode(1);
u8g2.clearBuffer();
for (int i = 0; i < 5; i++) {
pinMode(sw_pin[i], INPUT_PULLUP);
}
// Display the icons
u8g2.drawXBMP(0, 7, 48, 48, bitmap_wifi_100);
u8g2.drawXBMP(48, 7, 32, 48, bitmap_battery_charge);
u8g2.drawXBMP(80, 7, 48, 48, bitmap_session_disconnected);
u8g2.sendBuffer();
// setPowerSave(0);
}
// ----------------------------------------------------------------
// ---------------------------- Loop ------------------------------
// ----------------------------------------------------------------
void loop() {
if (menuindex == 0) {
if (getSw('L')) {
u8g2.clearBuffer();
u8g2.drawStr(30,30,"LEFT");
//u8g2.updateDisplayArea(30,30,40,10);
u8g2.sendBuffer();
}
if (getSw('R')) {
u8g2.clearBuffer();
u8g2.drawStr(30,30,"RIGHT");
//u8g2.updateDisplayArea(30,30,40,10);
u8g2.sendBuffer();
}
if (getSw('U')) {
u8g2.clearBuffer();
u8g2.drawStr(30,30,"UP");
//u8g2.updateDisplayArea(30,30,40,10);
u8g2.sendBuffer();
}
if (getSw('D')) {
u8g2.clearBuffer();
u8g2.drawStr(30,30,"DOWN");
//u8g2.updateDisplayArea(30,30,40,10);
u8g2.sendBuffer();
}
if (getSw('E')) {
u8g2.clearBuffer();
u8g2.drawStr(30,30,"ENTER");
//u8g2.updateDisplayArea(30,30,40,10);
u8g2.sendBuffer();
}
}
} // loop
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
oled1:DATA
oled1:CLK
oled1:DC
oled1:RST
oled1:CS
oled1:3V3
oled1:VIN
oled1:GND
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
btn4:1.l
btn4:2.l
btn4:1.r
btn4:2.r
btn5:1.l
btn5:2.l
btn5:1.r
btn5:2.r