#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Animation control
unsigned long lastSwitch = 0;
int animIndex = 0;
const int animDuration = 5000; // milliseconds per animation
// Animation variables
int scrollX = SCREEN_WIDTH;
int ballX = 0, ballY = 0, dx = 2, dy = 2;
int wavePhase = 0;
int starY = SCREEN_HEIGHT;
int pulseSize = 0;
bool pulseGrow = true;
void setup() {
Wire.begin(); // Default I2C pins for Arduino Uno/Nano/Mega
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
}
void loop() {
unsigned long now = millis();
if (now - lastSwitch > animDuration) {
animIndex = (animIndex + 1) % 5;
lastSwitch = now;
scrollX = SCREEN_WIDTH;
ballX = 0; ballY = 0; dx = 2; dy = 2;
wavePhase = 0;
starY = SCREEN_HEIGHT;
pulseSize = 0; pulseGrow = true;
display.clearDisplay();
}
switch (animIndex) {
case 0: animateScrollingText(); break;
case 1: animateBouncingBall(); break;
case 2: animateWave(); break;
case 3: animateFallingStar(); break;
case 4: animatePulseCircle(); break;
}
delay(30);
}
// ------------------ Animation 1: Scrolling Text ------------------
void animateScrollingText() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(scrollX, 30);
display.println("Enper Education");
display.display();
scrollX -= 2;
if (scrollX < -100) scrollX = SCREEN_WIDTH;
}
// ------------------ Animation 2: Bouncing Ball ------------------
void animateBouncingBall() {
display.clearDisplay();
display.fillCircle(ballX, ballY, 5, SSD1306_WHITE);
display.display();
ballX += dx;
ballY += dy;
if (ballX <= 0 || ballX >= SCREEN_WIDTH - 5) dx = -dx;
if (ballY <= 0 || ballY >= SCREEN_HEIGHT - 5) dy = -dy;
}
// ------------------ Animation 3: Sine Wave ------------------
void animateWave() {
display.clearDisplay();
for (int x = 0; x < SCREEN_WIDTH; x++) {
int y = 32 + 20 * sin((x + wavePhase) * 0.1);
display.drawPixel(x, y, SSD1306_WHITE);
}
wavePhase += 2;
display.display();
}
// ------------------ Animation 4: Falling Star ------------------
void animateFallingStar() {
display.clearDisplay();
display.fillTriangle(64, starY, 60, starY + 10, 68, starY + 10, SSD1306_WHITE);
display.display();
starY -= 2;
if (starY < -10) starY = SCREEN_HEIGHT;
}
// ------------------ Animation 5: Pulsing Circle ------------------
void animatePulseCircle() {
display.clearDisplay();
display.fillCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, pulseSize, SSD1306_WHITE);
display.display();
if (pulseGrow) {
pulseSize++;
if (pulseSize > 20) pulseGrow = false;
} else {
pulseSize--;
if (pulseSize < 2) pulseGrow = true;
}
}