#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <ArduinoTrace.h>
#include "Bitmaps.h"
#include "Font.h"
// Define the number of devices we have in the chain and the hardware interface
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
//#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
// Global data
typedef struct
{
textEffect_t effect; // text effect to display
char * psz; // text string nul terminated
uint16_t speed; // speed multiplier
uint16_t pause; // pause multiplier
} sCatalog;
// sCatalog catalog[] =
// {
// { PA_PRINT, "PRINT", 1, 1 },
// { PA_SLICE, "SLICE", 1, 1 },
// { PA_MESH, "MESH", 10, 1 },
// { PA_FADE, "FADE", 20, 1 },
// { PA_WIPE, "WIPE", 3, 1 },
// { PA_WIPE_CURSOR, "WPE_C", 4, 1 },
// { PA_OPENING, "OPEN", 3, 1 },
// { PA_OPENING_CURSOR, "OPN_C", 4, 1 },
// { PA_CLOSING, "CLOSE", 3, 1 },
// { PA_CLOSING_CURSOR, "CLS_C", 4, 1 },
// { PA_RANDOM, "RAND", 3, 1 },
// { PA_BLINDS, "BLIND", 7, 1 },
// { PA_DISSOLVE, "DSLVE", 7, 1 },
// { PA_SCROLL_UP, "SC_U", 5, 1 },
// { PA_SCROLL_DOWN, "SC_D", 5, 1 },
// { PA_SCROLL_LEFT, "SC_L", 5, 1 },
// { PA_SCROLL_RIGHT, "SC_R", 5, 1 },
// { PA_SCROLL_UP_LEFT, "SC_UL", 7, 1 },
// { PA_SCROLL_UP_RIGHT, "SC_UR", 7, 1 },
// { PA_SCROLL_DOWN_LEFT, "SC_DL", 7, 1 },
// { PA_SCROLL_DOWN_RIGHT, "SC_DR", 7, 1 },
// { PA_SCAN_HORIZ, "SCNH", 6, 1 },
// { PA_SCAN_HORIZX, "SCNHX", 6, 1 },
// { PA_SCAN_VERT, "SCNV", 6, 1 },
// { PA_SCAN_VERTX, "SCNVX", 6, 1 },
// { PA_GROW_UP, "GRW_U", 7, 1 },
// { PA_GROW_DOWN, "GRW_D", 7, 1 },
// };
sCatalog catalog[] =
{
{ PA_DISSOLVE, "@ @", 15, 5 },
{ PA_SCROLL_RIGHT, "&", 5, 0 },
{ PA_BLINDS, "|$$$", 10, 3 },
{ PA_SCROLL_RIGHT, ":) :) :) :) :)", 3, 1 },
};
uint16_t SnowSpeed;
uint16_t AnimationSpeed;
uint16_t BellAnimationSpeed;
void setup()
{
Serial.begin(57600);
AnimationSpeed=200;
BellAnimationSpeed=200;
SnowSpeed=100;
for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)
{
catalog[i].speed *= 10;
catalog[i].pause *= 500;
}
P.begin();
P.setFont(myFont);
P.addChar('&', Sleigh);
P.setInvert(false);
P.addChar('$', XTree);
P.addChar('|', VBlankLine);
// Bell Animations
P.addChar('6', Bell1);
P.addChar('7', Bell2);
P.addChar('8', Bell3);
P.addChar('9', Bell4);
P.addChar('0', Bell5);
P.addChar('@', Baubles);
}
void loop()
{
for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)
{
if(SpecialAnimations(catalog[i].psz)==false)
{
P.displayText(catalog[i].psz, PA_CENTER, catalog[i].speed, catalog[i].pause, catalog[i].effect, catalog[i].effect);
while (!P.displayAnimate())
; // animates and returns true when an animation is completed
}
delay(catalog[i].pause);
}
}
bool SpecialAnimations(char *Code)
{
// returns true if performed a special animaton (based on code) else false
if((Code=="BELL")|(Code=="SNOW")|(Code=="STARS"))
{
if(Code=="BELL")
AnimateBell();
if(Code=="SNOW")
Snow();
if(Code=="STARS")
FlashingStars();
return true;
}
else
return false;
}
void AnimateBell()
{
for(int i=0;i<1;i++)
{
P.displayText("||||6",PA_LEFT,0,AnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("|||7",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||8",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||9",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||0",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||||||9",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("||||||8",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("|||7",PA_LEFT,0,BellAnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
}
}
void FlashingStars()
{
for(int i=0;i<8;i++)
{
P.displayText("* + *",PA_CENTER,0,AnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
P.displayText("+ * +",PA_CENTER,0,AnimationSpeed,PA_PRINT,PA_NO_EFFECT);
while (!P.displayAnimate());
}
}
void Snow()
{
P.displayText("* * *",PA_CENTER,SnowSpeed,0,PA_SCROLL_DOWN,PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText(" * *",PA_CENTER,SnowSpeed,0,PA_SCROLL_DOWN,PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText("* * * *",PA_CENTER,SnowSpeed,0,PA_SCROLL_DOWN,PA_SCROLL_DOWN);
while (!P.displayAnimate());
P.displayText("* * *",PA_CENTER,SnowSpeed,0,PA_SCROLL_DOWN,PA_SCROLL_DOWN);
while (!P.displayAnimate());
}