// Program to demonstrate the MD_Parola library
// MD_MAX72XX library can be found at https://github.com/MajicDesigns/MD_MAX72XX
//
//Using Zones to display counter digits, with intention to apply
//up or down scroll effect on each digit on change
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define NUM_ZONES 5
#define CLK_PIN 13//Arduino UNO spi pins
#define DATA_PIN 11
#define CS_PIN 10
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
// Global variables
char newCount [6] = {"00000"};
char oldCount [6] = {"99999"};
char zonesStr [6] = {"01234"};
char thisWord [15];
const char *nums [10] = {"0","1","2","3","4","5","6","7","8","9"};
const char *letter [27] = {"SPACE","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
uint8_t c = 0;
uint8_t letterNum1[5] = {8,5,12,12,15};
uint8_t letterNum2[5] = {23,15,18,12,4};
uint32_t startTime = 0;
uint16_t count = 0;
void setup(void)
{
Serial.begin(115200);
P.begin(NUM_ZONES);
P.setInvert(false);
//P.setIntensity(0);//Doesn't work properly here
// set the zone boundaries
P.setZone(0, 0, 3);
P.setIntensity(0);//OK here
P.setZone(1, 3, 3);
P.setZone(2, 2, 2);
P.setZone(3, 1, 1);
P.setZone(4, 0, 0);
P.displayClear();
P.displayReset();
for (uint8_t i = 0; i < 27; i++) {
if (i % 2 == 0) {
P.displayZoneText(0, letter[i], PA_CENTER, 30, 200, PA_SCROLL_LEFT, PA_SCROLL_UP);
while (!P.displayAnimate()){};
P.displayReset();
Serial.print(letter[i]);
}
else
{
P.displayZoneText(0, letter[i], PA_CENTER, 30, 200, PA_SCROLL_RIGHT, PA_SCROLL_DOWN);
while (!P.displayAnimate()){};
P.displayReset();
Serial.print(letter[i]);
}
}
Serial.println();
for (uint8_t i = 0; i < 5; i++) {
sprintf(thisWord,"%s%s",thisWord,letter[letterNum1[i]]);
Serial.println(thisWord);
P.displayZoneText(0, thisWord, PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
delay(500);
}
P.displayClear();
thisWord[0] = 0;
for (uint8_t i = 0; i < 5; i++) {
sprintf(thisWord,"%s%s",thisWord,letter[letterNum2[i]]);
Serial.println(thisWord);
P.displayZoneText(0, thisWord, PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
delay(500);
}
P.displayClear();
for (uint8_t n = 1; n < 5; n++) {//To display the Zone number/order are set correctly
P.displayZoneText(n, nums[n], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
Serial.print(nums[n]);
delay(1000);
}
Serial.println();
P.displayZoneText(0, zonesStr, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.displayAnimate();
delay(1000);
}
void doCounter() {
Serial.println(oldCount);
Serial.println(newCount);
for (uint8_t i = 1; i < 5; i ++) {
if (newCount[i] != oldCount[i]) {
c = char(newCount[i] - 48);
P.displayZoneText(i, nums[c], PA_CENTER, 40, 0, PA_SCROLL_DOWN, PA_NO_EFFECT);
Serial.print("Zone ");
Serial.print(i);
Serial.print(" ");
Serial.print("Print ");
Serial.print("C");
Serial.print(newCount[i]);
Serial.print(" Index");
Serial.println(c);
} else {
Serial.print("Zone ");
Serial.print(i);
Serial.print(" ");
Serial.print("Do nowt ");
Serial.print("C");
Serial.print(newCount[i]);
Serial.print(" Index");
Serial.println(c);
}
}
strcpy(oldCount, newCount);
count ++;
if (count == 10000) count = 0;
sprintf(newCount, "%05d", count);//Rollover tested, works fine.
P.synchZoneStart();
}
void loop(void) {
if (P.displayAnimate()) {
if (millis() - startTime >= 1000) {
startTime = millis();
doCounter();
}
}
}