#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
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
//#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_ZONES 10
const int DATA_PIN = 11, CLK_PIN = 13; // DATA PIN et CLOCK PIN Communes aux 6 matrices
// CS_PIN = CS (Chip Select) pour chaque matrice.
const int CS_PIN_M1 = 10, CS_PIN_M2 = 9, CS_PIN_M3 = 8, CS_PIN_M4 = 7, CS_PIN_M5 = 6;
//combien de matrices 8x8 avons-nous dans une chaîne (12 dans notre cas )
const int MAX_DEVICES = 12; //nombre d'appareils que nous avons dans la chaîne et l'interface matérielle
//définir les broches utilisées pour se connecter à l'Arduino
//Ayant tout cela défini, nous pouvons également déclarer le module lui-même "Matrice_1"
MD_Parola Matrice_1 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M1, MAX_DEVICES); //matrice 1
MD_Parola Matrice_2 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M2, MAX_DEVICES); //matrice 2
MD_Parola Matrice_3 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M3, MAX_DEVICES); //matrice 3
MD_Parola Matrice_4 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M4, MAX_DEVICES); //matrice 4
MD_Parola Matrice_5 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN_M5, MAX_DEVICES); //matrice 5
/* Nous définissons la structure qui stocke toutes les informations
nécessaires pour exécuter l'animation.*/
struct animations
{
textEffect_t anim_in; // Type d'animation d'entrée
textEffect_t anim_out; // Type d'animation de sortie
const char * textOut; // Texte à afficher
uint16_t speed; // Vitesse d'animation (multiplicateur par défaut de la bibliothèque)
uint16_t pause; // pause (multiplicateur pour la bibliothèque par défaut)
textPosition_t just;
};
//Et en utilisant cette structure, nous pouvons créer le tableau
//qui stockerait l’animation composite.
animations Animation[] =
{ // { Anime INPUT , Anime OUTPUT , Texte à afficher , Speed,Pause,Alignement}
/* index 0 */ { PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Cipad 60e Edition", 4, 5, PA_CENTER },
/* index 1 */ { PA_SLICE, PA_GROW_DOWN, "J'aime", 1, 2, PA_CENTER },
/* index 2 */ { PA_RANDOM, PA_GROW_DOWN, "Partagez", 1, 2, PA_CENTER},
/* index 3 */ { PA_SCROLL_LEFT, PA_SCROLL_LEFT, "Abonne toi !", 5, 0, PA_LEFT},
/* index 4 */ { PA_BLINDS, PA_GROW_DOWN, "Ez-Weekend-Projects", 12, 5, PA_CENTER},
/* index 5 */ { PA_SCROLL_DOWN_LEFT, PA_SCROLL_DOWN_LEFT, "Aurevoir", 4, 2, PA_LEFT},
/* index 6 */ { PA_SCROLL_UP_RIGHT, PA_SCROLL_UP_RIGHT, "et", 4, 2, PA_CENTER},
/* index 7 */ { PA_SCROLL_DOWN_RIGHT, PA_SCROLL_DOWN_RIGHT, "a bientot!", 4, 2, PA_RIGHT}
};
/*Voici la liste des animations de texte prédéfinies avec leurs identifiants
que vous utiliseriez dans le code:
PA_PRINT PA_SCROLL_UP PA_SCROLL_DOWN PA_SCROLL_LEFT PA_SCROLL_RIGHT
PA_SPRITE PA_SLICE PA_MESH PA_FADE PA_DISSOLVE PA_BLINDS PA_RANDOM
PA_WIPE PA_WIPE_CURSOR PA_SCAN_HORIZ PA_SCAN_HORIZX PA_SCAN_VERT
PA_SCAN_VERTX PA_OPENING PA_OPENING_CURSOR PA_CLOSING PA_CLOSING_CURSOR
PA_SCROLL_UP_LEFT PA_SCROLL_UP_RIGHT PA_SCROLL_DOWN_LEFT PA_SCROLL_DOWN_RIGHT
PA_GROW_UP PA_GROW_DOWN */
void setup() {
lcd.init(); lcd.backlight(); // initialise et active le rétroéclairage de lcd.
Matrice_1.begin(); // démarrage de la matrice 1
Matrice_2.begin(); // démarrage de la matrice 2
Matrice_3.begin(); // démarrage de la matrice 3
Matrice_4.begin(); // démarrage de la matrice 4
Matrice_5.begin(); // démarrage de la matrice 5
/*Lors de la configuration, initialisez les modules MAX7219 ainsi
que le temps et la pause pour chaque application.*/
for (uint8_t i = 0; i < ARRAY_SIZE(Animation); i++)
{
// initialiser
Animation[i].speed *= Matrice_1.getSpeed(); Animation[i].pause *= 500;
}
}
void loop() {
/*En boucle, nous parcourons le tableau avec des animations
en les affichant une par une.
Et les affichons à l'aide de la fonction displayText.*/
static uint8_t i = 0; // index des effets de texte
//displayMatrice_2(i);
if (Matrice_1.displayAnimate())// anime et renvoie vrai lorsqu'une animation est terminée
{
if (i == ARRAY_SIZE(Animation))i = 0; // réinitialiser l'index de la boucle
displayInfos(i);
Matrice_1.displayText(Animation[i].textOut, //Text à afficher
Animation[i].just, //Alignement
Animation[i].speed, // Vitesse d'animation (multiplicateur par défaut de la bibliothèque)
Animation[i].pause, //Pause (durée d'affichage)
Animation[i].anim_in, //Animation en entrée
Animation[i].anim_out); //Animation en sortie
delay(1000); //Marque une pause de 1 seconde avant de passer à l'animation suivante
i++; // Incrémente de 1 L'index
}
}
void displayInfos(int index) {
//String Pause =Animation[index].pause;
Matrice_2.setTextAlignment(PA_CENTER);
Matrice_2.print("Animation[" + String(index) + "]");
Matrice_3.setTextAlignment(Animation[index].just);
Matrice_3.print("Alignement: " + String(Animation[index].just));
Matrice_4.setTextAlignment(PA_CENTER);
Matrice_4.print(String(Animation[index].speed) + " / " + String(Animation[index].pause));
Matrice_5.setTextAlignment(PA_CENTER);
Matrice_5.print(String(Animation[index].anim_in) + " / " + String(Animation[index].anim_out));
}