#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold18pt7b.h>
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
//wifi icon size: 20W*15H px
const unsigned char wifi_icon [] PROGMEM = {
0x07, 0xc0, 0x1f, 0xf0, 0x7c, 0x7c, 0x70, 0x1c,
0xc0, 0x06, 0xc3, 0x86, 0x0f, 0xe0, 0x1c, 0x70,
0x18, 0x30, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80
};
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
//reset OLED display via software
pinMode(OLED_RST, OUTPUT);
digitalWrite(OLED_RST, LOW);
delay(20);
digitalWrite(OLED_RST, HIGH);
//initialize OLED
Wire.begin(OLED_SDA, OLED_SCL);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);
display.print("WIFI");
display.setCursor(0,10);
display.print("PWR");
display.drawRect(40, 9, display.width()-40, 10, WHITE);
display.fillRect(40, 9, 50 , 10, WHITE);
display.setCursor(0,20);
display.print("Button");
display.drawCircle(48,24, 4, WHITE);
display.drawCircle(60,24, 4, WHITE);
display.drawBitmap(113, 50, wifi_icon, 15, 12, 1);
display.display();
Serial.println("LoRa Sender Test");
delay(2000);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
display.fillCircle(48,24, 3, WHITE);
display.fillCircle(60,24, 3, INVERSE);
Serial.println("ON");
display.display();
delay(2000);
display.fillCircle(48,24, 3, INVERSE);
display.fillCircle(60,24, 3, WHITE );
Serial.println("OFF");
display.display();
delay(2000);
}
void drawBatteryIndicator(int percentage) {
// Draw battery outline
display.drawRect(110, 0, 18, 10, WHITE);
// Calculate the width of the battery indicator based on the percentage
int batteryWidth = map(percentage, 0, 100, 0, 16);
// Draw filled battery indicator
display.fillRect(112, 2, batteryWidth, 6, WHITE);
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1
Loading
ssd1306
ssd1306