Last active
May 18, 2023 12:20
-
-
Save tablatronix/2e7c956e39a34919bc0c9fc05fad0219 to your computer and use it in GitHub Desktop.
dirty scroll text for adafruit gfx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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