#include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // Base text String prefix = " Simon says: "; // space before Simon String baseMsg = "Hello world"; String msg = baseMsg; int x = SCREEN_WIDTH; void setup() { if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { for(;;); // stop if no display } display.clearDisplay(); } void loop() { // Scroll current message across the screen display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(x, 20); display.print(prefix + msg); display.display(); // Move left x--; if (x < -( (prefix.length() + msg.length()) * 6 )) { // Finished scrolling x = SCREEN_WIDTH; // Drop first character from msg, reset if empty if (msg.length() > 1) { msg.remove(0, 1); } else { msg = baseMsg; } } delay(30); }