#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// Create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const char* textToSlide = "Robotronix"; // Text to slide
int textX = SCREEN_WIDTH; // Initial X position
void setup() {
Serial.begin(9600);
// Initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("Failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // Wait two seconds for initializing
oled.clearDisplay(); // Clear display
oled.setTextSize(1); // Set text size
oled.setTextColor(WHITE); // Set text color
oled.setCursor(textX, 2); // Set initial position to display (x,y)
oled.println(textToSlide); // Set initial text
oled.display(); // Display on OLED
}
void loop() {
// Clear the display
Adafruit_ImageReader reader;
reader
oled.clearDisplay();
// Update the text position
textX--;
// If the text has scrolled off the screen, reset its position
if (textX < -strlen(textToSlide) * 6) {
textX = SCREEN_WIDTH;
}
// Set the new text position and display it
oled.setCursor(textX, 2);
oled.println(textToSlide);
oled.display();
delay(50); // Adjust the delay for scrolling speed
}