#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int SCREEN_WIDTH = 128; // OLED display width, in pixels
const int SCREEN_HEIGHT = 64; // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
while(true);
}
display.clearDisplay();
display.display();
}
void loop() {
display.clearDisplay();
// Draw the battery outline
display.drawRoundRect(18, 18, 86, 28, 5, SSD1306_WHITE);
display.drawRoundRect(19, 19, 84, 26, 3, SSD1306_WHITE);
display.fillRect(104, 27, 2, 10, SSD1306_WHITE);
display.fillRoundRect(104, 27, 3, 10, 1, SSD1306_WHITE);
display.display();
delay(500);
for(int i = 0; i < 5; i++) {
display.fillRoundRect(22 + i*16, 22, 14, 20, 2, SSD1306_WHITE);
display.display();
delay(300); // Delay between each segment
}
// Keep the battery full for a bit
delay(1000);
}