#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Ball parameters
int ballX1 = 0; // Left ball starts from the left edge
int ballX2 = SCREEN_WIDTH; // Right ball starts from the right edge
int ballY = SCREEN_HEIGHT / 2; // Vertical center
int ballRadius = 4;
int xSpeed = 3;
bool expanding = false;
bool showText = false;
void setup() {
// Initialize display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed if initialization fails
}
display.clearDisplay();
}
void loop() {
display.clearDisplay();
if (!expanding) {
// Move balls toward the center
ballX1 += xSpeed; // Left ball moves right
ballX2 -= xSpeed; // Right ball moves left
// Check if balls have met at the center
if (ballX1 >= SCREEN_WIDTH / 2 - ballRadius && ballX2 <= SCREEN_WIDTH / 2 + ballRadius) {
expanding = true; // Start expanding when balls meet
showText = true; // Display text immediately when balls meet
} else {
// Draw the two moving balls
display.fillCircle(ballX1, ballY, ballRadius, SSD1306_WHITE);
display.fillCircle(ballX2, ballY, ballRadius, SSD1306_WHITE);
}
} else {
// Expand merged ball and display "rootXpert" text
ballRadius += 2; // Expand faster by increasing radius by 2
// Draw expanding circle at the center
display.fillCircle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, ballRadius, SSD1306_WHITE);
// Show "rootXpert" immediately once balls meet
if (showText) {
display.setTextColor(SSD1306_BLACK); // Set text color to black
display.setTextSize(1);
display.setCursor((SCREEN_WIDTH - 54) / 2, SCREEN_HEIGHT / 2 - 4); // Center "rootXpert"
display.print("rootXpert");
}
// Stop expanding when radius reaches screen width
if (ballRadius >= SCREEN_WIDTH / 2) {
return; // Stop the animation loop
}
}
display.display();
delay(20); // Adjust delay for animation speed
}