#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Right eye OLED at I2C address 0x3D
#define SCREEN_ADDRESS 0x3D
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 rightEyeDisplay(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Eye properties
int rightEyeX = 64;
int rightEyeY = 32;
int rightPupilX = rightEyeX;
int rightPupilY = rightEyeY;
bool rightEyeBlinking = false;
unsigned long lastRightBlink = 0;
unsigned long rightBlinkInterval = 3000; // blink every 3 seconds
unsigned long rightBlinkDuration = 200; // blink duration
void setup() {
Wire.begin(8, 9); // SDA = 8, SCL = 9 for ESP32-S3
if (!rightEyeDisplay.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("Right Eye OLED not found at 0x3D!");
while (true);
}
rightEyeDisplay.clearDisplay();
rightEyeDisplay.display();
}
void loop() {
unsigned long now = millis();
// Handle blinking logic
if (!rightEyeBlinking && now - lastRightBlink > rightBlinkInterval) {
rightEyeBlinking = true;
lastRightBlink = now;
}
if (rightEyeBlinking && now - lastRightBlink > rightBlinkDuration) {
rightEyeBlinking = false;
lastRightBlink = now;
}
// Pupil movement (demo: sinusoidal)
rightPupilX = rightEyeX + 10 * sin(now / 300.0);
rightPupilY = rightEyeY + 5 * cos(now / 300.0);
drawRightEye();
}
void drawRightEye() {
rightEyeDisplay.clearDisplay();
if (rightEyeBlinking) {
// Draw closed eye (a line)
rightEyeDisplay.drawLine(24, rightEyeY, 104, rightEyeY, SSD1306_WHITE);
} else {
// Draw eye outline
rightEyeDisplay.drawCircle(rightEyeX, rightEyeY, 20, SSD1306_WHITE);
// Draw pupil
rightEyeDisplay.fillCircle(rightPupilX, rightPupilY, 5, SSD1306_WHITE);
}
rightEyeDisplay.display();
}
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1