// Projet de session 2022
// ==============================================
/*
--------------------------------------------------------------------------
Projet: Projet de session 2022
Auteur: Olivier Roux
Date: 2022.11.25
---------------------------------------------------------------------------
Description: Programme envoyant un message communiquant par UART à l'aide d'un ILI9341 ainsi qu'un écran lcd 20x04.
Permettant d'afficher l'heure actuelle exacte à l'aide d'un RTC et d'un 4 Digit Display
---------------------------------------------------------------------------
Début du programme: 2022.11.25
Porsuite du programme: 2022.11.26
Porsuite du programme: 2022.11.27
Porsuite du programme: 2022.11.28
Porsuite du programme: 2022.11.29
Porsuite du programme: 2022.11.30
Fin du programme: 2022.12.01
---------------------------------------------------------------------------
*/
// ==============================================
#include "mesincludes.h"
// Déclaration des objets à portée globale:
TM1637 affichageHorloge(CLK, DIO);
DS1307 horloge;
Adafruit_ILI9341 ecranCentraleSurveillance = Adafruit_ILI9341(TFT_CS, TFT_DC);
LiquidCrystal_I2C ecranPrincipal(ADRESSE_I2C,NB_COLONES_ECRAN_LCD,NB_LIGNES_ECRAN_LCD);
// ********************************************************
void setup()
// ********************************************************
{
// Initialisation des modules
Serial.begin(9600);
Serial << (F(MSG_DEMARRAGE_DU_PROJET));
Serial << (F(MSG_PROJET_PAR));
Serial << (F(MSG_DEBUT_INIT));
initialisationDesAppareils();
Serial << (F(MSG_FIN_INIT));
afficherPageEcran(centraleEcranOuverture);
afficherPageEcran(ecranOuverture, UNE_SECONDE * 2);
afficherPageEcran(ecranInstruction);
afficherTemps();
// Début de Lecture du bouton et affichage de l'heure en mode non bloquant
int nbrFoisBtn = 0;
while(nbrFoisBtn == 0)
{
if (digitalRead(PIN_BTN))
{
Serial << "Bouton enfoncé\n";
delay(5);
// Permet d'éviter que le bouton reste enfoncé
nbrFoisBtn++;
while (digitalRead(PIN_BTN));
delay(5);
}
}
// Fin de Lecture du bouton
if (connexionALaCentrale()){
afficherPageEcran(systemeEnLigne);
}
} // setup()
// ********************************************************
void loop()
// ********************************************************
{
afficherTemps();
} // loop()
// ********************************************************
void afficherPageEcran(Ecrans ecran, int delai = 0)
// ********************************************************
{
switch(ecran)
{
// Affichage du premier écran
case ecranOuverture:
ecranPrincipal.backlight();
ecranPrincipal.setCursor(0,0);
ecranPrincipal.print(F(alarme));
ecranPrincipal.setCursor(0,1);
ecranPrincipal.print(F(ligne));
ecranPrincipal.setCursor(0,2);
ecranPrincipal.print(F(version));
ecranPrincipal.setCursor(0,3);
ecranPrincipal.print(F(matricule));
Serial << "afficherPageEcran\n";
break;
// Affichage du premier écran sur le ILI9341
case centraleEcranOuverture:
Serial << "Debut ecranCentraleSurveillance\n";
ecranCentraleSurveillance.setCursor(26, 26);
ecranCentraleSurveillance.setTextColor(ILI9341_RED);
ecranCentraleSurveillance.setTextSize(3);
ecranCentraleSurveillance.print(MSG_CENTRALE_SURVEILLANCE);
ecranCentraleSurveillance.setCursor(10, 80);
ecranCentraleSurveillance.setTextColor(ILI9341_WHITE);
ecranCentraleSurveillance.setTextSize(2);
ecranCentraleSurveillance.print(LIGNE_ILI9341);
ecranCentraleSurveillance.setCursor(0, 110);
ecranCentraleSurveillance.setTextColor(ILI9341_YELLOW);
ecranCentraleSurveillance.print(MESSAGE_ATTENTE_CLIENT);
Serial << "Fin ecranCentraleSurveillance\n";
break;
// Affichage du deuxième écran du LCD
case ecranInstruction:
delay(DEUX_SECONDES);
Serial << "Debut ecranInstruction\n";
ecranPrincipal.clear();
ecranPrincipal.print(MESSAGE_LIGNE1_ECRAN2);
ecranPrincipal.setCursor(0,1);
ecranPrincipal.print(MESSAGE_LIGNE2_ECRAN2);
ecranPrincipal.setCursor(0,2);
ecranPrincipal.print(MESSAGE_LIGNE3_ECRAN2);
ecranPrincipal.setCursor(0,3);
ecranPrincipal.print(MESSAGE_LIGNE4_ECRAN2);
Serial << "Fin ecranInstruction\n";
break;
// Affichage de la troisième écran sur les deux dispositifs
case systemeEnLigne:
Serial << "Debut systemeEnLigne\n";
ecranPrincipal.clear();
ecranPrincipal.setCursor(2,0);
ecranPrincipal.print(MESSAGE_SYSTEME_EN_LIGNE);
ecranPrincipal.setCursor(0,1);
ecranPrincipal.print(ligne);
ecranPrincipal.setCursor(0,2);
ecranPrincipal.print(MESSAGE_FIN_ETAPE1);
ecranPrincipal.setCursor(0,3);
ecranPrincipal.print(ligne);
ecranCentraleSurveillance.setCursor(0, 158);
ecranCentraleSurveillance.print(MESSAGE_SYSTEME_EN_LIGNE);
Serial << "Fin systemeEnLigne\n";
break;
} // switch(ecran)
} // afficherPageEcran()
// ********************************************************
void initialisationDesAppareils()
// ********************************************************
{
//Initialisation du UART de la centrale
Serial3.begin(UART_VITESSE_CONSOLE3);
//Initialisation du UART du système d alarme
Serial1.begin(UART_VITESSE_CONSOLE1);
//Initilisation du LCD
ecranPrincipal.begin(NB_COLONES_ECRAN_LCD, NB_LIGNES_ECRAN_LCD);
//Initialisation du TFT
ecranCentraleSurveillance.begin();
//Initialisation du bouton
pinMode(PIN_BTN, INPUT);
//Initialisation du 4-digit
affichageHorloge.init();
//Initialisation du RTC
horloge.begin();
} // initialisationDesAppareils()
// ********************************************************
boolean connexionALaCentrale()
// ********************************************************
{
// Retourner 'true' ou 'false' selon le cas.
Serial1.write(1);
delay(1000);
if(Serial3.available())
{
return true;
}
return false;
} // connexionALaCentrale()
// ********************************************************
void afficherTemps()
// ********************************************************
{
horloge.fillByHMS(15, 24, 45);
//horloge.setTime();
horloge.getTime();
affichageHorloge.set(BRIGHT_TYPICAL);
// Division du temps pour l'afficher correctement sur le 4 Digits
affichageHorloge.display(0,horloge.hour / 10);
affichageHorloge.display(1,horloge.hour % 10);
affichageHorloge.display(2,horloge.minute / 10);
affichageHorloge.display(3,horloge.minute % 10);
affichageHorloge.point(true);
} // afficherTemps()