#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include "Font_Data.h"
textEffect_t scrollMid, scrollLower;
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define NUM_ZONES 3
#define ZONE_SIZE 12
#define MAX_DEVICES (NUM_ZONES * ZONE_SIZE)
#define ZONE_UPPER 2
#define ZONE_MID 1
#define ZONE_LOWER 0
#define PAUSE_TIME 2000
#define SCROLL_SPEED 20
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 3
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
const char *msgL[] = {"3 months, 25 days, 22 hours"};
const char *msgU[] = {"Another text for Zone Upper"};
char *msgH; // allocated memory in setup()
void setup(void)
{
uint8_t max = 0;
for (uint8_t i = 0; i < ARRAY_SIZE(msgL); i++)
if (strlen(msgL[i]) > max) max = strlen(msgL[i]);
for (uint8_t i = 0; i < ARRAY_SIZE(msgU); i++)
if (strlen(msgU[i]) > max) max = strlen(msgU[i]);
msgH = (char *)malloc(sizeof(char) * (max + 2));
P.begin(NUM_ZONES);
for (int i = 0; i < NUM_ZONES; i++)
P.setZone(i, i * ZONE_SIZE, (i + 1) * ZONE_SIZE - 1);
P.setFont(BigFont);
P.setCharSpacing(P.getCharSpacing() * 2); // double height --> double spacing
}
void createHString(char *pH, const char *pL)
{
for (; *pL != '\0'; pL++)
*pH++ = *pL | 0x80; // offset character
*pH = '\0'; // terminate the string
}
void loop(void)
{
static uint8_t cycle = 0;
P.displayAnimate();
if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_MID) && P.getZoneStatus(ZONE_UPPER))
{
createHString(msgH, msgL[cycle]);
P.displayClear();
P.displayZoneText(ZONE_LOWER, msgL[cycle], PA_LEFT, SCROLL_SPEED, PAUSE_TIME, PA_SCROLL_LEFT, PA_WIPE_CURSOR);
P.displayZoneText(ZONE_MID, msgH, PA_LEFT, SCROLL_SPEED, PAUSE_TIME, PA_SCROLL_LEFT, PA_WIPE_CURSOR);
P.displayZoneText(ZONE_UPPER, msgU[cycle], PA_LEFT, SCROLL_SPEED, PAUSE_TIME, PA_SCROLL_LEFT, PA_WIPE_CURSOR);
cycle = (cycle + 1) % ARRAY_SIZE(msgL);
P.synchZoneStart();
}
}