I'm working on a project with a Adafruit 8x16 LED Matrix FeatherWing, which I want to use to display scrolling text. Looking at the example code provided via the Arduino library, I've managed to come up with the following:
void updateDisplay()
{
for (int8_t x = 16; x >= -36; x--)
{
matrix.clear();
matrix.setCursor(x, 0);
matrix.print("World");
// matrix.print(displayText);
matrix.writeDisplay();
delay(100);
}
}
Nothing too different from the sample code, except I've set x
to 16
so the message starts from off the display on the left.
If I understand this correctly, the -36
value is how many pixels is required to scroll the text off the other side of the display. That is to say, the buffer for "World" is 36
pixels wide. If this is the case, how can I work out the size of the buffer for an arbitrary string?
I'm guessing there's a method which I'm able to write (or exists) which can calculate it, or maybe the library already knows this info, in which case I need a way to access it.
You can see I have a displayText
variable which I'm going to be updating with a duration, anything from "0 seconds" to "365 days" (and beyond), so I'm going to need to calculate this width each time the displayText
value is updated - unless there's an easier way to solve this problem?
I welcome your advice, thank you.