#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
if(!display.begin( SSD1306_PAGEADDR, SEEK_SET)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display(); // Clear the display
delay(2000);
display.clearDisplay(); // Clear the buffer
}
void loop() {
display.clearDisplay(); // Clear the buffer
static int16_t xPos = 0;
static int16_t xSpeed = 2;
// Draw a moving line
display.drawLine(xPos, 0, xPos, SCREEN_HEIGHT - 1, WHITE);
// Update position
xPos += xSpeed;
// Check boundaries
if (xPos >= SCREEN_WIDTH || xPos <= 0) {
xSpeed = -xSpeed; // Reverse direction
}
display.display(); // Display the buffer
delay(500); // Adjust the delay for animation speed
}