#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const int EYE_Y = 20;
const int EYE_W = 16;
const int GAP = 16;
void face(bool closed, int offset, int jump, bool smile) {
display.clearDisplay();
int left = 64 - GAP / 2 - EYE_W + offset;
int right = 64 + GAP / 2 + offset;
int y = EYE_Y - jump;
int height = closed ? 2 : 16;
display.fillRoundRect(left, y, EYE_W, height, closed ? 0 : 4, SSD1306_WHITE);
display.fillRoundRect(right, y, EYE_W, height, closed ? 0 : 4, SSD1306_WHITE);
if (smile) {
display.drawLine(54, 43 - jump, 59, 48 - jump, SSD1306_WHITE);
display.drawLine(59, 48 - jump, 69, 48 - jump, SSD1306_WHITE);
display.drawLine(69, 48 - jump, 74, 43 - jump, SSD1306_WHITE);
}
display.display();
}
void setup() {
Serial.begin(115200);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("OLED init failed"));
while (true) { delay(100); }
}
Serial.println(F("OLED ready"));
}
void loop() {
face(false, 0, 0, true);
delay(50);
}
Loading
ssd1306
ssd1306
Uno: USB 5V (simulation)