#include <MD_Parola.h> // inclure la bibliothèque MajicDesigns Parola
#include <MD_MAX72xx.h> // inclure la bibliothèque de matrices LED MajicDesigns MAX72xx
#include <SPI.h> // inclure la bibliothèque Arduino SPI
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
// DATA PIN et CLOCK PIN Communes aux 4 matrices
const int DATA_PIN = 11, CLK_PIN = 13;
// CS (Chip Select) pour chaque matrice.
const int CS_PIN_M1 = 10, CS_PIN_M2 = 9;
// Combien de matrices 8x8 avons-nous dans une chaîne,
const int MAX_DEVICES_M1 = 15, // (12 chaînes pour la matrice_1),
MAX_DEVICES_M2 = 15; // (15 pour la matrice_2),
// MATÉRIEL SPI: Définir les PINS utilisés connecter chaque matrice à l'Arduino
MD_Parola Matrice_1 = // Nom de la Matrice 1
MD_Parola(HARDWARE_TYPE, // Type de matériel
DATA_PIN, // Broche DATA (commune à toutes les matrices)
CLK_PIN, // Broche Clock (commune à toutes les matrices)
CS_PIN_M1, // Broche CS (Chip Select) diffèrente pour chaque matrice.
MAX_DEVICES_M1); // nombre maximal de chaînes pour cette matrice
MD_Parola Matrice_2 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M2, MAX_DEVICES_M2); // Matrice 2
// Tampons de messages globaux partagés par les fonctions série et de défilement
#define BUF_SIZE 75 // longeur du tampon
static uint8_t txtEffectIn = 0; // Mode d'affichage actuel
static uint8_t txtEffectOUT = 0; // Mode d'affichage actuel
/*
Ensuite, nous définissons la structure qui
stocke toutes les informations nécessaires
pour exécuter l'animation.
c.à.d:
le type d'animation avec lequel le texte arrive,
le type d'animation avec lequel le texte repart
le texte lui-même que l'on souhaite animer,
la vitesse de l'animation,
la pause entre l'arrivée et le départ
l'alignement du texte.
*/
struct animations
{
textEffect_t anim_in; // Type d'animation en entrant
textEffect_t anim_out;// Type d'animation en sortant
const char * textOut; // Texte à afficher
uint16_t speed; // Vitesse d'animation (multiplicateur pour la valeur par défaut de la bibliothèque)
uint16_t pause; // pause (multiplicateur pour la valeur par défaut de la bibliothèque)
textPosition_t just;
};
/*Et en utilisant cette structure,
nous pouvons créer le tableau qui stockerait l’animation composite.*/
animations animList[] = {
//{ anim_in , anim_out , textOut , speed,pause, aligmenent}
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Merci de regarder Cipad......................... C.I.P.A.D est une serie de Cours d'Initiation à la Programmation Arduino pour debutants. ", 4, 0, PA_LEFT },
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Production: Canadienne de Ez-Weekend-Projects", 4, 0, PA_LEFT },
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Realisation: Daniel Talbot Technicien ", 4, 0, PA_LEFT },
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Commandite: Le Club Technique des Laurentides", 4, 0, PA_LEFT },
{ PA_MESH, PA_GROW_DOWN, "SI VOUS AVEZ AIMEZ", 1, 2, PA_CENTER },
{ PA_MESH, PA_GROW_DOWN, "Cliquez sur J'AIME", 1, 4, PA_CENTER },
{ PA_RANDOM, PA_GROW_DOWN, "PARTAGEZ", 1, 2, PA_CENTER},
{ PA_SCROLL_LEFT, PA_SCROLL_LEFT, "S'abonner", 5, 0, PA_LEFT},
{ PA_BLINDS, PA_GROW_DOWN, "CIPAD", 2, 2, PA_CENTER},
{ PA_SCROLL_DOWN_LEFT, PA_SCROLL_DOWN_LEFT, "AUREVOIR", 4, 2, PA_LEFT},
{ PA_SLICE, PA_SCROLL_UP_RIGHT, "ET", 4, 2, PA_RIGHT},
{ PA_SCROLL_DOWN_RIGHT, PA_BLINDS, "A BIENTOT!", 1, 10, PA_CENTER}
};
char curMessage[BUF_SIZE] = { "" };
char Message1[BUF_SIZE] = { "Zone 1" };
char Message2[BUF_SIZE] = { "Zone 2" };
char Message3[BUF_SIZE] = { "Zone 3" };
char Message4[BUF_SIZE] = { "CIPAD 61e Edition" };
char Message5[BUF_SIZE] = { "TxtEffet_IN:" };
static uint8_t i = 0; // text effect index
static uint8_t display = 0; // Mode d'affichage actuel
static uint8_t speed = 0; // vitesse d'exécution
char buffer[20];
void setup() {
// démarage des matrices
Matrice_1.begin(); Matrice_2.begin();
// initialisation de la variable "i" (index) d'après
// la taille du tableau animList
for (uint8_t i = 0; i < ARRAY_SIZE(animList); i++)
{ // initialise la vitesse et la pause de chaque élément contenu dans le tableau animList
animList[i].speed *= Matrice_1.getSpeed(); // vitesse
animList[i].pause *= 500; // durée de la pause multipliée pas 500ms.
}
}
void loop() {
// initialisation();
displayExemple(); // Affiche un exemple de plusieurs animations préprogrammées
}
void displayMatrice_1() {
Matrice_1.displayAnimate();
if (Matrice_1.getZoneStatus(0))
{
txtEffectIn++; if (txtEffectIn > 29)txtEffectIn = 0;
switch (txtEffectIn) {
case 1: speed = 25; break;
case 6: speed = 150; break;
case 7: speed = 0; break;
case 8: speed = 149; break;
case 12: speed = 25; break;
case 13: speed = 50; break;
case 14: speed = 20; break;
default : speed = 25; break;
}
Matrice_1.displayText(Message4, PA_CENTER, speed, 1000, txtEffectIn, txtEffectIn);
}
}
void displayMatrice_2() {
Matrice_2.displayAnimate();
if (Matrice_2.getZoneStatus(0)) {
char buffer2[20];
//int Eff_In =animList[i].anim_in;
sprintf(buffer2, "Speed: %2d Pause: %4d",
animList[i].speed,
//animList[i].anim_in,
animList[i].pause *= 500);
//animList[i].anim_out);
Matrice_2.displayText(buffer2, // Texte à afficher
PA_LEFT, // Alignement
0, // Vitesse d'excution
0, // Pause (durée d'affichage)
PA_PRINT, // Animation en entrée
PA_NO_EFFECT); // Animation en sortie
Matrice_2.displayReset(0);
}
}
/*
void displayMatrice_3() {
Matrice_2.displayAnimate();
if (Matrice_3.getZoneStatus(0)) {
sprintf(buffer, "Speed: %d ", animList[i].speed);
Matrice_3.displayText(buffer, // Texte à afficher
PA_LEFT, // Alignement
0, // Vitesse d'excution
0, // Pause (durée d'affichage)
PA_PRINT, // Animation en entrée
PA_NO_EFFECT); // Animation en sortie
Matrice_3.displayReset(0);
}
}
*/
void displayExemple() {
if (Matrice_1.displayAnimate())// animates and returns true when an animation is completed
{
if (i == ARRAY_SIZE(animList))i = 0; // reset loop index
Matrice_1.displayText(animList[i].textOut,
animList[i].just,
animList[i].speed,
animList[i].pause,
animList[i].anim_in,
animList[i].anim_out);
delay(1000);
i++; // then set up for next text effect
}
}