#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
// Updated left and right arrow bitmaps (24x24)
const uint8_t leftArrow[] = {
0xff, 0xc7, 0xff, 0xff, 0x83, 0xff, 0xff, 0x80, 0xff, 0x7f, 0x80, 0xff, 0x3f, 0xc0, 0xff, 0x1f,
0xe0, 0xff, 0x0f, 0xf0, 0xff, 0x07, 0xf8, 0xff, 0x03, 0xfc, 0xff, 0x01, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0xc0, 0x07, 0xf8, 0xff,
0x0f, 0xf0, 0xff, 0x1f, 0xe0, 0xff, 0x3f, 0xc0, 0xff, 0x7f, 0x80, 0xff, 0xff, 0x80, 0xff, 0xff,
0x81, 0xff, 0xff, 0x83, 0xff, 0xff, 0xc7, 0xff
};
const uint8_t rightArrow[] = {
0xff, 0xe3, 0xff, 0xff, 0xc1, 0xff, 0xff, 0x01, 0xff, 0xff, 0x01, 0xfe, 0xff, 0x03, 0xfc, 0xff,
0x07, 0xf8, 0xff, 0x0f, 0xf0, 0xff, 0x1f, 0xe0, 0xff, 0x3f, 0xc0, 0x01, 0x00, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x03, 0x00, 0xc0, 0xff, 0x1f, 0xe0,
0xff, 0x0f, 0xf0, 0xff, 0x07, 0xf8, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xfe, 0xff, 0x01, 0xff, 0xff,
0x81, 0xff, 0xff, 0xc1, 0xff, 0xff, 0xe3, 0xff
};
// Define Wi-Fi symbol bitmap (16x16)
const uint8_t wifiIcon[] = {
0x00, 0x00, 0x00, 0x18, 0x18, 0x24, 0x24, 0x42, 0x42, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Variables
int batteryLevel = 90;
int throttleSpeed = 45;
bool frontLight = false;
bool backLight = false;
bool leftSignal = false;
bool rightSignal = false;
bool blinkState = false;
unsigned long previousMillis = 0;
const long interval = 500;
void setup() {
Serial.begin(9600);
u8g2.begin();
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
}
void loop() {
unsigned long currentMillis = millis();
frontLight = digitalRead(2);
backLight = digitalRead(3);
leftSignal = digitalRead(4);
rightSignal = digitalRead(5);
if (leftSignal || rightSignal) {
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
blinkState = !blinkState;
}
} else {
blinkState = false;
}
u8g2.clearBuffer();
// Display throttle information at the top
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setCursor(0, 10);
u8g2.print("Throttle: ");
u8g2.print(throttleSpeed);
u8g2.print("%");
// Display arrows with blinking effect in respective corners only when signal is ON
if (leftSignal && blinkState) {
u8g2.drawXBM(0, 15, 24, 24, leftArrow); // Left arrow at top left corner
}
if (rightSignal && blinkState) {
u8g2.drawXBM(100, 15, 24, 24, rightArrow); // Right arrow at top right corner
}
// Display Wi-Fi icon in the top right corner
u8g2.drawXBM(104, 0, 16, 16, wifiIcon); // Wi-Fi icon at the top right corner
// Display lights status below arrows
u8g2.setCursor(0, 55);
u8g2.print("Lgt: ");
u8g2.print(frontLight ? "F " : "- ");
u8g2.print(backLight ? "B " : "- ");
// Display battery level at the bottom
u8g2.setCursor(50, 55);
u8g2.print("Battery: ");
u8g2.print(batteryLevel);
u8g2.print("%");
u8g2.sendBuffer();
// Simulate throttle speed and battery level for testing purposes
throttleSpeed = (throttleSpeed + 1) % 101;
batteryLevel = max(0, batteryLevel - 1);
delay(500);
}