Open prabbit237 opened 4 months ago
Actually, a "pause/resume" is already implemented (even if it wasn't intended to be such.) A quick test showed that the following code will pause the scrolling for 10 seconds simply by changing the speed to 0.
...
scrollingLayer1.setSpeed(15);
scrollingLayer1.start("SmartMatrix & FastLED", 2);
while (scrollingLayer1.getStatus())
{
delay(10000);
scrollingLayer1.setSpeed(0);
delay(10000);
scrollingLayer1.setSpeed(15);
}
"Don't call it a bug and fix it. Leave it as-is and call it a feature!" Me: Hey, support, my computer keeps getting a BSOD! What gives? Fix this issue!!!11!!!!!1!!!!!! MS Support: It's not a bug. It's a great new feature in Windows that encourages you to take a break from work every hour or so.
This was the code I came up with for the time display on my project where I'm using the two suggested new functions of getPosition() and getTextWidth().
void xTaskDisplayTime(void *pvParameters)
{
// The task is created before matrix.begin to allow for any allocation of stack space, etc.
// So the pertinent section of code in setup(void) is:
//
// xTaskCreate(
// xTaskDisplayTime,
// "DisplayTime",
// 10000,
// NULL,
// 1,
// NULL);
// matrix.addLayer(&backgroundLayer);
// matrix.addLayer(&timeScrollLayer);
// matrix.begin();
// matrixIsStarted = true;
// Then this while() simply holds it here till matrix.begin() has run so that it doesn't try to use the matric too early.
while (!matrixIsStarted)
vTaskDelay(1);
byte lastSecond = 60;
timeScrollLayer.setMode(wrapForward);
timeScrollLayer.setOffsetFromTop(3);
timeScrollLayer.setSpeed(20);
timeScrollLayer.setFont(font8x13);
String timeNow;
for (;;)
{
if (lastSecond!=tz.second())
{
lastSecond = tz.second();
// Let's change the colors as the seconds pass.
timeScrollLayer.setColor({0xff - (lastSecond * 4), 0xff, 0x0F + (lastSecond * 4)});
if (!tz.second())
{
// Make sure any previous time has scrolled back off first.
// This also means at boot, it'll not show the time for
// up to 60 seconds :(
timeScrollLayer.setSpeed(20);
while (timeScrollLayer.getStatus())
vTaskDelay(25);
//now let's scroll in the new time
timeNow = tz.dateTime("g:ia");
timeScrollLayer.start((char *)&timeNow[0], 1);
//self-centering no matter what font is used
while (timeScrollLayer.getPosition()>(kMatrixWidth - timeScrollLayer.getTextWidth())/2)
//need to keep this delay short to avoid overshooting the target
vTaskDelay(10);
timeScrollLayer.setSpeed(0);
}
}
// Wait for the next cycle.
vTaskDelay(50);
// Perform action here. xWasDelayed value can be used to determine
// whether a deadline was missed if the code here took too long.
}
}
Exposing the text width and scroll position of a scrolling layer would be nice to have.
Use-case:
That would make the time scroll out to centered on the screen and then "freeze." A minute later, the time starts scrolling again to the right and disappears.
Adding scroll.pause() and scroll.resume() functions as well would make the above sample even easier as there'd be no mucking about with the indexed layer and saving the position, etc. It would be just:
Other use-cases would include a sign that scrolls across "Now serving #12. Now serving #12" and as each "#12" reaches the middle, and indexed later above it prints "#12" in a different color, pauses, clears it and then resumes the scroll. Thus making it more noticeable via the blink (written as I look at my own ticket with # 4633668346 on it, sigh and try to remember if I still have that pillow in the car since I'm going to be here for a while.)