// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
// ESP32 - LCD/I2C
// ---------------
// 3.3V - Vcc
// GND - GND
// 22 - SCL
// 21 - SDA
#include <WiFi.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 20, 4);
uint8_t SEG_D[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111};
uint8_t SEG_A[8] = {0b11111, 0b11111, 0b11111, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000};
uint8_t SEG_DG[8] = {0b11111, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111};
uint8_t SEG_AG[8] = {0b11111, 0b11111, 0b11111, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111};
uint8_t SEG_GU[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111};
uint8_t SEG_GD[8] = {0b11111, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000};
uint8_t DOT[8] = {0b00000, 0b00000, 0b00000, 0b01100, 0b01100, 0b00000, 0b00000, 0b00000};
uint8_t DEG[8] = {0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000, 0b00000};
void digSeg(byte x, byte y, byte z1, byte z2, byte z3, byte z4, byte z5, byte z6) {
LCD.setCursor(x, y);
LCD.write(z1); LCD.write(z2); LCD.write(z3);
LCD.setCursor(x, y + 1);
LCD.write(z4); LCD.write(z5); LCD.write(z6);
}
void drawDigit(byte digit, byte col, byte row) {
switch (digit) {
case 0:
digSeg(col, row, 255, 2, 255, 255, 1, 255);
break;
case 1:
digSeg(col, row, 32, 32, 255, 32, 32, 255);
break;
case 2:
digSeg(col, row, 3, 3, 255, 255, 0, 0);
break;
case 3:
digSeg(col, row, 3, 3, 255, 0, 0, 255);
break;
case 4:
digSeg(col, row, 255, 6, 255, 7, 7, 255);
break;
case 5:
digSeg(col, row, 255, 3, 3, 0, 0, 255);
break;
case 6:
digSeg(col, row, 255, 3, 3, 255, 0, 255);
break;
case 7:
digSeg(col, row, 2, 2, 255, 32, 32, 255);
break;
case 8:
digSeg(col, row, 255, 3, 255, 255, 0, 255);
break;
case 9:
digSeg(col, row, 255, 3, 255, 0, 0, 255);
break;
}
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.createChar(0, SEG_DG);
LCD.createChar(1, SEG_D);
LCD.createChar(2, SEG_A);
LCD.createChar(3, SEG_AG);
LCD.createChar(6, SEG_GU);
LCD.createChar(7, SEG_GD);
LCD.createChar(4, DOT);
LCD.createChar(5, DEG);
LCD.setCursor(0, 0);
LCD.print("Ready !");
delay(1000);
LCD.clear();
for (byte i = 0; i < 5; i++) {
drawDigit (i, i * 4, 0);
drawDigit (i + 5, i * 4, 2);
}
// LCD.print(" THU");
// LCD.setCursor(0, 3);
// LCD.print("23.5");
// LCD.write(5);//degree symbol
// LCD.print("C");
// LCD.setCursor(7, 3);
// LCD.print("SUNNY");
}
void loop() {
LCD.setCursor(7, 0);
LCD.write(32);
LCD.setCursor(7, 1);
LCD.write(32);
delay(500);
LCD.setCursor(7, 0);
LCD.write(4);
LCD.setCursor(7, 1);
LCD.write(4);
delay(500);
}