I am using 4 number of 16x32 P10 LED in a combination of 32x64 - 2 Row and 2 Column.
I need to display two sliding animations on each row. Example - 1st row should display "HELLO TEAM" sliding text and 2nd row should display "WELCOME" sliding text.
with reference to this forum - Play different Animations at a time - DMD P10
I am successfully able to play different animations at a time but facing difficulty in playing two different sliding animation at the same time.
Please help.
Code for different animation at a time -
void setup()
{
Timer1.initialize( 4000 ); // I find the default 5000 gives a visible flicker
Timer1.attachInterrupt( ScanDMD );
dmd.selectFont(SystemFont5x7);
dmd.clearScreen( true ); // start with a blank screen
dmd.drawMarquee("HELLO TEAM!",strlen("HELLO TEAM!"),0, 4);
}
void loop()
{
int event_len1 = calStringWidth("TOGGLE");
int event_len2 = calStringWidth("TEXT");
if(topActive == false){
topActive = true;
}
if (topActive && (millis() - lastTimeTop >= topPeriod)) {
topActive =! dmd.stepSplitMarquee(0,16); // parameters are the top & bottom rows to be scrolled
lastTimeTop = millis();
}
if (bottomActive && (millis() - lastTimeBottom >= bottomPeriod)) {
dmd.drawString(event_len1,17,"TOGGLE",strlen("TOGGLE"),GRAPHICS_TOGGLE); // the stationary string
dmd.drawString(event_len2,25,"TEXT",strlen("TEXT"),GRAPHICS_TOGGLE); // the stationary string
lastTimeBottom = millis();
}
}
I have added this part because once the sliding is finished, topActive =! dmd.stepSplitMarquee(0,16); the stepSplitMarquee func makes the topActive false, to start the sliding again, we reset the flag.
below is the complete code -
#include "SPI.h"
#include "DMD.h"
#include "TimerOne.h"
#include "SystemFont5x7.h"
#include "Arial14.h"
#define DISPLAYS_ACROSS 2
#define DISPLAYS_DOWN 2
DMD dmd( DISPLAYS_ACROSS , DISPLAYS_DOWN);
const char* name = "Hello Jane!";
const char* event = "Toggle Text";
const uint32_t topPeriod = 50;
uint32_t lastTimeTop = -topPeriod;
bool topActive = true;
const uint32_t bottomPeriod = 500;
uint32_t lastTimeBottom = -bottomPeriod;
bool bottomActive = true;
void ScanDMD()
{
dmd.scanDisplayBySPI();
}
void setup()
{
Timer1.initialize( 4000 ); // I find the default 5000 gives a visible flicker
Timer1.attachInterrupt( ScanDMD );
dmd.selectFont(SystemFont5x7);
dmd.clearScreen( true ); // start with a blank screen
Serial.begin(9600);
dmd.drawMarquee("HELLO JANE!",strlen("HELLO JANE!"),0, 4);
}
int stringWidth(const char *bChars)
{
int strWidth = 0;
for (byte i = 0; i < strlen(bChars); i++) { // step through the length of the string
strWidth += dmd.charWidth(bChars[i]) + 1; // increment by the width of this character in pixels,
// plus the 1 pixel character spacing
}
return strWidth - 1; // don't allow for a character space at the end
}
int calStringWidth(const char* thisWord) {
int Xstart = 31 - (stringWidth(thisWord) / 2); // work out where to display the first character
if (0 > Xstart) Xstart = 0;
return Xstart;
}
void loop()
{
int event_len1 = calStringWidth("Toggle");
int event_len2 = calStringWidth("Text");
if(topActive == false){
topActive = true;
}
if (topActive && (millis() - lastTimeTop >= topPeriod)) {
topActive =! dmd.stepSplitMarquee(0,16); // parameters are the top & bottom rows to be scrolled
lastTimeTop = millis();
}
if (bottomActive && (millis() - lastTimeBottom >= bottomPeriod)) {
dmd.drawString(event_len1,17,"Toggle",strlen("Toggle"),GRAPHICS_TOGGLE); // the stationary string
dmd.drawString(event_len2,25,"Text",strlen("Text"),GRAPHICS_TOGGLE); // the stationary string
lastTimeBottom = millis();
}
// here you have some business logic, non blocking. No delay
}
I'm not sure I understand the question. You just need to take one step in one row and take one step in the other row when it's due
const uint32_t topPeriod = 50;
uint32_t lastTimeTop = -topPeriod;
const uint32_t bottomPeriod = 500;
uint32_t lastTimeBottom = -bottomPeriod;
void setup() {
// set up the environment, display what you want to scroll
}
void loop()
{
if (millis() - lastTimeTop >= topPeriod) {
// here scroll the top one step
lastTimeTop = millis();
}
if (bottomActive && (millis() - lastTimeBottom >= bottomPeriod)) {
// here scroll the bottom one step
lastTimeBottom = millis();
}
}