123456789101112131415161718192021222324252627282930313233343536373839404142
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// 0x1306.dev · animation: eyes_glitch · robot_eyes · 83ms
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void drawEyes(int lx, int ly, int lw, int lh, int lr,
int rx, int ry, int rw, int rh, int rr) {
display.fillRoundRect(lx - lw/2, ly - lh/2, lw, lh, lr, WHITE);
display.fillRoundRect(rx - rw/2, ry - rh/2, rw, rh, rr, WHITE);
}
void drawFrame(int frame) {
display.clearDisplay();
int ox[] = {0, 2, -2, 4, -1, 0};
int oy[] = {0, -2, 3, -1, 2, 0};
if (frame % 3 == 0) {
drawEyes(32 + ox[frame], 32 + oy[frame], 38, 28, 8, 96 - ox[frame], 32 - oy[frame], 38, 28, 8);
} else {
display.clearDisplay();
display.fillRect(32 - 19, 32 - 2, 38, 4, WHITE);
display.fillRect(96 - 19, 32 - 2, 38, 4, WHITE);
display.display();
}
display.display();
}
void setup() {
Wire.begin(21, 22);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
for (int i = 0; i < 6; i++) {
drawFrame(i);
delay(83);
}
}