// FiveSeconds.ino
// Sketch from Arduino forum:
// https://forum.arduino.cc/t/animating-my-mx7219-4-digit-module-using-md-parola-md-max72xx-lib/952396
// With update of Reply #3.
//
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 3
//user defines/var
bool animate = 1;
unsigned long currentMillis = millis();
unsigned long previousMillis = millis();
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
uint8_t scrollSpeed = 25; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 2000; // in milliseconds
// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = {""};
char newMessage[BUF_SIZE] = {"Hello! Enter new message?"};
bool newMessageAvailable = true;
void setup()
{
Serial.begin(38400);
P.begin();
P.displayText(newMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
P.setIntensity(0);
}
void loop()
{
currentMillis = millis();
if (currentMillis - previousMillis > 5000)
{
previousMillis = currentMillis;
animate = !animate;
P.displayReset();
}
if (animate)
{
P.displayText(newMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
P.displayAnimate();
while (!P.displayAnimate());
}
else
{
P.print("static");
}
}