#include <Wire.h>//I2C stuff
#include <Adafruit_SSD1306.h>//oled oled stuff
#include <Adafruit_GFX.h>//Draw stuff on oled
Adafruit_SSD1306 oled(128, 64, &Wire, -1);//Declare oled type, size, connection and that it has no reset pin.
char message[] = "Oled roulette: Pressing the reset button may or may not crash the display";//Text to scroll
int x, minX;//Store position and length of text
void setup() {
Serial.begin(115200);
while (!Serial);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);//Start oled on I2C
x = oled.width();//Sets to 128 pixels width
minX = -18 * strlen(message);//18 = 6 pixels/character * text size 3
}
void loop() {
oled.clearDisplay();//Clear buffer and screen
oled.setTextColor(SSD1306_WHITE);//Use white pixels
oled.setTextSize(3);//Set 3 times normal text size
oled.setTextWrap(false);//Turn text wrapping off
oled.setCursor(x, 16);//Position cursor
oled.print(message);//Scrolling message
oled.display();//Send the above to the display
x = x - 3;//scroll speed, make more positive to slow down the scroll
Serial.println(x);
if (x < minX) x = oled.width();//If text length less than 128 pixels, use screen size as length to base scrolling maths on
}