Skip to content

Instantly share code, notes, and snippets.

@tablatronix
Last active May 18, 2023 12:20
Show Gist options
  • Save tablatronix/2e7c956e39a34919bc0c9fc05fad0219 to your computer and use it in GitHub Desktop.
Save tablatronix/2e7c956e39a34919bc0c9fc05fad0219 to your computer and use it in GitHub Desktop.
dirty scroll text for adafruit gfx
void scrollString(String str) {
int yoff = 1;
display.clearDisplay();
display.setTextWrap(false); // we don't wrap text so it scrolls nicely
display.setTextSize(2);
display.setRotation(0);
int charWidth = 12; // textsize 2 @todo auto calculate charwidth from font
int pxwidth = (str.length()*charWidth)+32; // @todo get actual string pixel length, add support to gfx if needed
for (int32_t x=charWidth; x>=-pxwidth; x--) {
display.clearDisplay();
display.setCursor(x,yoff);
// Serial.println((String)x);
// display.print("ABCDEFGHIJKLMNONPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789");
display.print(str);
// delay(ANIMSPEED/2);
delay(150);
}
Serial.println("done");
}
@tablatronix
Copy link
Author

tablatronix commented Dec 28, 2018

I think this works, I just whipped it togather, I usually just whip together scrolling code for different displays, I need to make an actual library function or class to reuse to take in env info, speed, scroll behaviors loop, multiple directions, start from offscreen (pad left), start from 0, and auto determine the sizes. There are probably better implementations of scrolling using gfx and a matrix using actual canvas matrices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment