#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//#include "DHT.h"
#include <RTClib.h>
#include "LedControl.h"
LedControl lc=LedControl(11,12,10,1);
//CARACTERE ARDUINO MAX7219
byte animationFrames[10][8] = {
{B00001100, B01000010, B10000001, B10000001, B10000001, B10000001, B01000010, B00111100}, // Frame 1
{B00110000, B01000010, B10000001, B10000001, B10000001, B10000001, B01000010, B00111100}, // Frame 2
{B00111100, B01000000, B10000000, B10000001, B10000001, B10000001, B01000010, B00111100}, // Frame 3
{B00111100, B01000010, B10000001, B10000000, B10000000, B10000001, B01000010, B00111100}, // Frame 4
{B00111100, B01000010, B10000001, B10000001, B10000001, B10000000, B01000000, B00111100}, // Frame 5
{B00111100, B01000010, B10000001, B10000001, B10000001, B10000001, B01000010, B00110000}, // Frame 6
{B00111100, B01000010, B10000001, B10000001, B10000001, B10000001, B01000010, B00001100}, // Frame 7
{B00111100, B01000010, B10000001, B10000001, B10000001, B00000001, B00000010, B00111100}, // Frame 8
{B00111100, B01000010, B10000001, B00000001, B00000001, B10000001, B00000010, B00111100}, // Frame 9
{B00111100, B00000010, B00000001, B10000001, B10000001, B10000001, B00000010, B00111100} // Frame 10
};
byte O[] = {B00000000,B00111100,B01000010,B01000010,B01000010,B01000010,B00111100,B00000000};
byte ALL[] = {B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111};
byte EX[] = {B00000000,B00010000,B00010000,B00010000,B00010000,B00000000,B00010000,B00000000};
byte A[] = {B00000000,B00111100,B00100100,B00100100,B00111100,B00100100,B00100100,B00000000};
byte N[] = {B00000000,B00100010,B00110010,B00101010,B00100110,B00100010,B00000000,B00000000};
byte Q[] = {B00000000,B00111100,B01000010,B01000010,B01000010,B01000110,B00111110,B00000001};
byte S[] = {B00000000,B00111100,B00100000,B00111100,B00000100,B00000100,B00111100,B00000000};
byte U[] = {B00000000,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000,B00000000};
byte CROIX[] = {B00000000,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B00000000};
byte OUI[] = {B00000000,B00000001,B00000010,B00000100,B10001000,B01010000,B00100000,B00000000};
byte ATTENTION[] = {B00000000,B00010000,B00010000,B00010000,B00010000,B000000,B00010000,B00000000};
byte PointInterrogations[] = {B00000000,B00111000,B00000100,B00001000,B00010000,B000000,B00010000,B00000000};
byte Uplad[] = {B00010000,B00010000,B00010000,B01010100,B00111000,B10010010,B10000010,B11111110};
byte Interdit[] = {B00111100,B01000010,B10100001,B10010001,B10001001,B10000101,B01000010,B00111100};
byte* symbols[] = {
O, CROIX, ALL, EX, CROIX, OUI, ATTENTION, PointInterrogations, Uplad, Interdit
};
unsigned long lastPageChangeTime = 0; // Variable pour stocker le moment du dernier changement de page
byte flame[8] = {
B00100,
B01110,
B01110,
B11111,
B11111,
B01110,
B01110,
B00100
};
RTC_DS1307 rtc;
//#define DHTPIN 2 // Broche à laquelle le capteur est connecté
//#define DHTTYPE DHT11 // DHT11 pour notre capteur
//DHT dht(DHTPIN, DHTTYPE);
unsigned long previousMillis4 = 0;
const long frameInterval = 200; // Time between frames in milliseconds
const long pauseInterval = 100; // Pause time between animation cycles in milliseconds
int currentFrame = 9;
bool inPause = false;
bool runAnimationLoading = LOW;
const int pinX = A1; // Joystick axe X
const int pinY = A2; // Joystick axe Y
const int pinSEL = 13; // Bouton SEL du joystick
unsigned long lastJoystickMoveTime = 0; // Variable pour mémoriser le temps de la dernière action du joystick
int previousDirectionJoystick = 0;
int startHour = 0;
int startMinute = 0;
int endHour = 0;
int endMinute = 0;
int duration = 3000;
unsigned long currentMillis4 = 0;
unsigned long currentMillis5 = 0;
unsigned long startTime = 0;
bool HourChoice = HIGH;
bool StartDateChoice = LOW;
bool programmateur_enable = LOW;
int previousTargetPage = 0;
int xAxisValue, yAxisValue, buttonState;
int DirectionJoystick; // 1: haut, 2: droite, 3: bas, 4: gauche
int RelaisPin = 2;
bool pompe_chauffage_state = LOW;
unsigned long chauffage_start_time = 0;
const unsigned long chauffage_duration = 5000; // 30 minutes en millisecondes
bool pompe_activate_on_thirty_minutes = false;
float current_page = 1;
int current_choice = 1;
int target_page = 1;
int fps = 100;
unsigned long lastHourChangeTime3 = 0;
unsigned long hourChangeDelay3 = 100; // Délai de 200 millisecondes entre chaque augmentation
// Déclaration de variables pour la temporisation de l'augmentation des minutes
unsigned long lastMinuteChangeTime3 = 0;
unsigned long minuteChangeDelay3 = 20; // Délai de 200 millisecondes entre chaque augmentation
bool previousButtonState = HIGH; // Variable pour mémoriser l'état précédent du bouton
LiquidCrystal_I2C lcd(0x27, 16, 2);
int i=0;
int j=0;
int randomnum;
byte customChar1[] = {
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F
};
byte customChar2[] = {
0x00,
0x00,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F,
0x1F
};
byte customChar3[] = {
0x00,
0x00,
0x00,
0x00,
0x1F,
0x1F,
0x1F,
0x1F
};
byte customChar4[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x1F,
0x1F
};
byte customChar5[] = {
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
};
byte upArrow[8] = {
0b00100,
0b01110,
0b10101,
0b00100,
0b00100,
0b00100,
0b00100,
0b00000
};
void setup() {
//dht.begin();
lcd.init();
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,3);
/* and clear the display */
lc.clearDisplay(0);
lcd.backlight();
lcd.createChar(5, upArrow);
lcd.createChar(0, customChar1);
lcd.createChar(1, customChar2);
lcd.createChar(2, customChar3);
lcd.createChar(3, customChar4);
lcd.createChar(4, customChar5);
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(10, 0);
lcd.write(byte(1));
lcd.setCursor(15, 1);
lcd.print(" ");
lcd.setCursor(0, 0);
Wire.begin(); // Initialiser l'interface I2C
Serial.begin(9600);
pinMode(RelaisPin, OUTPUT);
pinMode(pinX, INPUT);
pinMode(pinY, INPUT);
pinMode(pinSEL, INPUT_PULLUP); // Utilise la résistance de pull-up interne
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1); // Bloque le programme si le RTC n'est pas trouvé
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Décommenter la ligne suivante pour régler l'heure au moment de la compilation
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// Configurer la broche SQW pour générer un signal carré de 1Hz
rtc.writeSqwPinMode(DS1307_SquareWave1HZ);
write_symbole(0);
Serial.println("RTC trouver");
debut();
}
void loop() {
if (runAnimationLoading) {
if (inPause) {
if (currentMillis4 - previousMillis4 >= pauseInterval) {
previousMillis4 = currentMillis4;
inPause = false;
currentFrame = 9;
lc.clearDisplay(0); // Clear the display after pause
}
} else {
if (currentMillis4 - previousMillis4 >= frameInterval) {
previousMillis4 = currentMillis4;
displayFrame(animationFrames[currentFrame]);
currentFrame--;
if (currentFrame < 0) {
inPause = true;
}
}
}
}
unsigned long currentMillis4 = millis();
float delay_fps = 1.0 / (float)fps; // Conversion de fps en un nombre à virgule flottante
delay(delay_fps * 1000);
unsigned long currentMillis = millis();
DateTime now = rtc.now(); // Obtenir l'heure actuelle
/*a
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
*/
//float h = dht.readHumidity(); // Lire l'humidité
//float t = dht.readTemperature(); // Lire la température en Celsius
xAxisValue = analogRead(pinX);
yAxisValue = analogRead(pinY);
buttonState = digitalRead(pinSEL);
if (xAxisValue > 800) {
DirectionJoystick = 2;
} else if (xAxisValue < 300) {
DirectionJoystick = 4;
} else if (yAxisValue > 800) {
DirectionJoystick = 1;
} else if (yAxisValue < 300) {
DirectionJoystick = 3;
} else {
DirectionJoystick = 0;
}
if (current_page == 1) {
if (target_page == 1){
lcd.setCursor(0, 0);
lcd.print("-Modes");
lcd.setCursor(0, 1);
lcd.print("-Reglage");
}
if (target_page == 2){
lcd.setCursor(0, 0);
lcd.print("-Capteurs");
lcd.setCursor(0, 1);
lcd.print("-Programmateur");
}
if (target_page == 3){
lcd.setCursor(0, 0);
lcd.print("-Autre");
}
if (DirectionJoystick == 4){
current_choice = 2;
}
if (DirectionJoystick == 2){
current_choice = 1;
}
if (previousDirectionJoystick != DirectionJoystick && DirectionJoystick != 0) {
if ((previousDirectionJoystick == 0 && (DirectionJoystick == 2 || DirectionJoystick == 4)) || (previousDirectionJoystick != 0 && (previousDirectionJoystick == 2 || previousDirectionJoystick == 4))) {
if (target_page == 1) {
if (current_choice == 1) {
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
}
if (current_choice == 2) {
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
}
if (target_page == 2) {
if (current_choice == 1) {
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
}
if (current_choice == 2) {
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
}
}
}
previousDirectionJoystick = DirectionJoystick;
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) { // Double vérification
if (current_choice == 1 && target_page == 1) {
Serial.println("Modes");
current_page = 1.1;
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
target_page = 1;
current_choice = 1;
}
if (current_choice == 2 && target_page == 1) {
Serial.println("Réglages");
current_page = 1.2;
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
target_page = 1;
current_choice = 1;
}
if (target_page == 2 && current_choice == 1) {
Serial.println("Capteurs");
current_page = 1.3;
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
target_page = 1;
current_choice = 1;
}
if (target_page == 2 && current_choice == 2) {
Serial.println("Programmteur");
target_page = 1;
current_choice = 1;
current_page = 1.4;
}
if (target_page == 3) {
Serial.println("Reglage");
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
target_page = 1;
current_choice = 1;
current_page = 1.5;
}
delay(100); // Anti-bounce delay
}
}
previousButtonState = buttonState;
if (previousTargetPage != target_page) {
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
previousTargetPage = target_page;
}
unsigned long currentTime = millis();
if (currentTime - lastPageChangeTime >= 500) {
// Gestion des changements de pages
if (DirectionJoystick == 3) {
target_page++; // Passage à la page suivante
if (target_page > 3) { // Si nous dépassons la troisième page, revenons à la première
target_page = 1;
}
lastPageChangeTime = currentTime; // Mettre à jour le moment du dernier changement de page
} else if (DirectionJoystick == 1) {
target_page--; // Passage à la page précédente
if (target_page < 1) { // Si nous sommes en dessous de la première page, allons à la troisième
target_page = 3;
}
lastPageChangeTime = currentTime; // Mettre à jour le moment du dernier changement de page
}
}
// Mettre à jour l'état précédent du joystick
previousDirectionJoystick = DirectionJoystick;
}
// Page 1.1
if (current_page == 1.1) {
lcd.setCursor(0, 0);
lcd.print("-Courant");
lcd.setCursor(0, 1);
lcd.print("-Chauffage(30m)");
if (DirectionJoystick == 2) {
current_choice = 1;
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
}
if (DirectionJoystick == 4) {
current_choice = 2;
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) { // Double vérification
if (target_page == 1 && current_choice == 1) {
Serial.println("Courant");
current_page = 1.11;
lcd.clear();
current_choice = 1;
target_page = 1;
delay(200); // Anti-bounce delay
}
if (target_page == 1 && current_choice == 2) {
Serial.println("Chauffer pendant 30 m");
pompe_chauffage_state = HIGH;
chauffage_start_time = millis();
current_page = 1;
lcd.clear();
current_choice = 1;
pompe_activate_on_thirty_minutes = true;
target_page = 1;
delay(200); // Anti-bounce delay
delay(200); // Anti-bounce delay
}
}
}
previousButtonState = buttonState;
}
// Page 1.2
if (current_page == 1.2) {
if (target_page == 1) {
lcd.setCursor(0, 0);
lcd.print("-Chauffage");
lcd.setCursor(0, 1);
lcd.print("-Pompe");
}
if (target_page == 2) {
lcd.setCursor(0, 0);
lcd.print("-Retour");
}
if (DirectionJoystick == 2 && target_page == 1) {
current_choice = 1;
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
}
if (DirectionJoystick == 4 && target_page == 1) {
current_choice = 2;
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
if (DirectionJoystick == 3 && target_page == 1) {
target_page = 2;
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
current_choice = 1;
}
if (DirectionJoystick == 1 && target_page == 2) {
target_page = 1;
lcd.clear();
lcd.setCursor(15, 0);
lcd.print("<");
current_choice = 1;
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) { // Double vérification
if (target_page == 1 && current_choice == 1) {
current_page = 1.21;
lcd.clear();
lcd.print("Chauffage:off");
delay(100); // Anti-bounce delay
}
if (target_page == 1 && current_choice == 2) {
current_page = 1.22;
lcd.clear();
lcd.print("Pompe:off");
delay(100); // Anti-bounce delay
}
if (target_page == 2) {
lcd.clear();
current_choice = 1;
target_page = 1;
current_page = 1;
delay(300); // Anti-bounce delay
}
}
}
previousButtonState = buttonState;
}
// Page 1.3
if (current_page == 1.3) {
lcd.setCursor(0, 0);
lcd.print("-Temperature");
lcd.setCursor(0, 1);
lcd.print("-Niveau d'eau");
if (DirectionJoystick == 2) {
current_choice = 1;
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
}
if (DirectionJoystick == 4) {
current_choice = 2;
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
}
if (current_page == 1.21){
lcd.setCursor(0, 0);
if (DirectionJoystick == 1 || DirectionJoystick == 3) {
pompe_chauffage_state = !pompe_chauffage_state; // Inverse l'état
lcd.clear();
if (pompe_chauffage_state) {
lcd.clear();
lcd.print("Chauffage:on");
pompe_chauffage_state = 1;
delay(250);
} else {
lcd.clear();
lcd.print("Chauffage:off");
pompe_chauffage_state = 0;
delay(250);
}
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) { // Double vérification
lcd.clear();
current_choice = 1;
target_page = 1;
lcd.setCursor(15, 0);
lcd.print("<");
current_page = 1;
delay(100); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
if (current_page == 1.22){
lcd.setCursor(0, 0);
if (DirectionJoystick == 1 || DirectionJoystick == 3) {
pompe_chauffage_state = !pompe_chauffage_state; // Inverse l'état
lcd.clear();
if (pompe_chauffage_state) {
lcd.clear();
lcd.print("Pompe:on");
pompe_chauffage_state = 1;
delay(250);
} else {
lcd.clear();
lcd.print("pompe:off");
pompe_chauffage_state = 0;
delay(250);
}
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) { // Double vérification
lcd.clear();
current_choice = 1;
target_page = 1;
lcd.setCursor(15, 0);
lcd.print("<");
current_page = 1;
delay(100); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
if (current_page == 1.11) {
lcd.setCursor(0, 0);
lcd.print("Mode courant :");
lcd.setCursor(0, 1);
lcd.print("Active");
delay(2000);
lcd.clear();
current_page = 1;
target_page = 1;
current_choice = 1;
}
if (current_page == 1.12) {
lcd.setCursor(0, 0);
lcd.print("Chaleur:chaud");
lcd.setCursor(0, 1);
lcd.print("ACTIVE");
delay(2000);
lcd.clear();
current_page = 1;
target_page = 1;
current_choice = 1;
}
if (current_page == 1.31) {
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(12, 0);
//lcd.print(t);
lcd.setCursor(14, 0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("> : retours");
if (DirectionJoystick == 1 || DirectionJoystick == 3) {
current_page = 1;
current_choice = 1;
target_page = 1;
lcd.clear();
delay(200);
}
}
if (current_page == 1.4) {
lcd.setCursor(0, 0);
lcd.print("-Activer");
lcd.setCursor(0, 1);
lcd.print("-Regler");
if (DirectionJoystick == 2) {
current_choice = 1;
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
} else if (DirectionJoystick == 4) { // Utilisation de "else if" pour éviter des vérifications redondantes
current_choice = 2;
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) {
if (current_choice == 1){
current_page = 1.41;
lcd.clear();
delay(200);
}
if (current_choice == 2){
lcd.clear();
open_programmateur();
delay(200);
}
}
}
previousButtonState = buttonState;
}
if (current_page == 1.41) {
lcd.setCursor(0, 0);
if (programmateur_enable) {
lcd.setCursor(0, 0);
lcd.print("Prog : on");
}
else {
lcd.setCursor(0, 0);
lcd.print("Prog : off");
}
if (DirectionJoystick == 1 || DirectionJoystick == 3) {
lcd.clear();
if (programmateur_enable) {
lcd.setCursor(0, 0);
lcd.print("Prog : on");
}
else {
lcd.setCursor(0, 0);
lcd.print("Prog : off");
}
if (programmateur_enable) {
programmateur_enable = LOW;
}
else {
programmateur_enable = HIGH;
}
delay(200);
lcd.clear();
}
if (buttonState == LOW && previousButtonState == HIGH) { // Détection du clic
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
current_page = 1;
}
}
previousButtonState = buttonState;
}
// Page 1.42
if (current_page == 1.42) {
// ENDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
if (StartDateChoice == HIGH) {
lcd.setCursor(0, 0);
lcd.print("Fin> ");
lcd.setCursor(15, 0);
lcd.print(" ");
// Affichage des heures à partir de la position (7, 0)
lcd.setCursor(5, 0);
if (endHour < 10) {
lcd.print("0");
}
lcd.print(endHour);
// Affichage du séparateur ":" à la position (10, 0)
lcd.setCursor(8, 0);
lcd.print(":");
// Affichage des minutes à partir de la position (11, 0)
lcd.setCursor(9, 0);
if (endMinute < 10) {
lcd.print("0");
}
lcd.print(endMinute);
// Affichage de la flèche pour indiquer la sélection (heures ou minutes)
if (HourChoice) {
lcd.setCursor(5, 1);
lcd.write(byte(5)); // Afficher le caractère personnalisé
lcd.setCursor(8, 1);
lcd.print(" ");
} else {
lcd.setCursor(9, 1);
lcd.write(byte(5)); // Afficher le caractère personnalisé
lcd.setCursor(5, 1);
lcd.print(" ");
}
// Logique pour changer les heures et les minutes avec les boutons
unsigned long currentTime = millis();
if (currentTime - lastHourChangeTime3 >= hourChangeDelay3) {
if (DirectionJoystick == 2) {
if (HourChoice) {
endHour++;
if (endHour > 23) endHour = 0;
} else {
endMinute++;
if (endMinute > 59) endMinute = 0;
}
} else if (DirectionJoystick == 4) {
if (HourChoice) {
endHour--;
if (endHour < 0) endHour = 23;
} else {
endMinute--;
if (endMinute < 0) endMinute = 59;
}
}
lastHourChangeTime3 = currentTime; // Mettre à jour le dernier temps de changement
}
// Logique pour sélectionner les heures ou les minutes
if (DirectionJoystick == 3) {
HourChoice = true;
}
if (DirectionJoystick == 1) {
HourChoice = false;
}
// Logique pour revenir à la page précédente
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
current_page = 1.421;
/*
Serial.print("Heure debut:");
Serial.print(startHour);
Serial.print("Minute debut:");
Serial.print(startMinute);
Serial.println(" ");
Serial.print("Heure fin:");
Serial.print(endHour);
Serial.print("Minute fin:");
Serial.print(endMinute);*/
delay(300); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
// STARTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
if (StartDateChoice == LOW) {
lcd.setCursor(0, 0);
lcd.print("Debut> ");
lcd.setCursor(15, 0);
lcd.print(" ");
// Affichage des heures à partir de la position (7, 0)
lcd.setCursor(7, 0);
if (startHour < 10) {
lcd.print("0");
}
lcd.print(startHour);
// Affichage du séparateur ":" à la position (10, 0)
lcd.setCursor(10, 0);
lcd.print(":");
// Affichage des minutes à partir de la position (11, 0)
lcd.setCursor(11, 0);
if (startMinute < 10) {
lcd.print("0");
}
lcd.print(startMinute);
// Affichage de la flèche pour indiquer la sélection (heures ou minutes)
if (HourChoice) {
lcd.setCursor(7, 1);
lcd.write(byte(5)); // Afficher le caractère personnalisé
lcd.setCursor(10, 1);
lcd.print(" ");
} else {
lcd.setCursor(11, 1);
lcd.write(byte(5)); // Afficher le caractère personnalisé
lcd.setCursor(7, 1);
lcd.print(" ");
}
// Logique pour changer les heures et les minutes avec les boutons
unsigned long currentTime = millis();
if (currentTime - lastHourChangeTime3 >= hourChangeDelay3) {
if (DirectionJoystick == 2) {
if (HourChoice) {
startHour++;
if (startHour > 23) startHour = 0;
} else {
startMinute++;
if (startMinute > 59) startMinute = 0;
}
} else if (DirectionJoystick == 4) {
if (HourChoice) {
startHour--;
if (startHour < 0) startHour = 23;
} else {
startMinute--;
if (startMinute < 0) startMinute = 59;
}
}
lastHourChangeTime3 = currentTime; // Mettre à jour le dernier temps de changement
}
// Logique pour sélectionner les heures ou les minutes
if (DirectionJoystick == 3) {
HourChoice = true;
}
if (DirectionJoystick == 1) {
HourChoice = false;
}
// Logique pour revenir à la page précédente
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
StartDateChoice = HIGH;
delay(300); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
}
if (current_page == 1.421){
lcd.setCursor(0, 0);
lcd.print("Hr.debut:");
lcd.setCursor(9, 0);
lcd.print(startHour);
lcd.setCursor(11, 0);
lcd.print(":");
lcd.setCursor(12, 0);
lcd.print(startMinute);
lcd.setCursor(0, 1);
lcd.print("Hr.fin:");
lcd.setCursor(7, 1);
lcd.print(endHour);
lcd.setCursor(9, 1);
lcd.print(":");
lcd.setCursor(10, 1);
lcd.print(endMinute);
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Changement");
lcd.setCursor(0, 1);
lcd.print("reussi !");
delay(1000); // Anti-bounce delay
lcd.clear();
current_page = 1;
}
}
previousButtonState = buttonState;
}
if (current_page == 1.5) {
lcd.setCursor(0, 0);
lcd.print("FPS");
lcd.setCursor(0, 1);
lcd.print("Informations");
if (DirectionJoystick == 2) {
current_choice = 1;
lcd.setCursor(15, 0);
lcd.print("<");
lcd.setCursor(15, 1);
lcd.print(" ");
} else if (DirectionJoystick == 4) {
current_choice = 2;
lcd.setCursor(15, 1);
lcd.print("<");
lcd.setCursor(15, 0);
lcd.print(" ");
}
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
if (current_choice == 1) {
lcd.clear();
current_page = 1.51;
} else if (current_choice == 2) {
lcd.clear();
current_page = 1.52;
}
}
}
previousButtonState = buttonState;
}
if (current_page == 1.51) {
lcd.setCursor(0, 0);
lcd.print("Changer FPS");
lcd.setCursor(0, 1);
lcd.print("fps actuelle:");
lcd.setCursor(13, 1);
lcd.print(fps);
// Code pour changer le FPS
if ((DirectionJoystick == 2 || DirectionJoystick == 4) && millis() - lastJoystickMoveTime > 150) {
if (DirectionJoystick == 2) {
fps++;
} else if (DirectionJoystick == 4) {
fps--;
if (fps < 1) fps = 1; // FPS minimum de 1 pour éviter division par zéro
}
lcd.setCursor(13, 1);
lcd.print(" ");
lcd.print(fps);
lastJoystickMoveTime = millis();
}
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
current_page = 1;
delay(200); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
if (current_page == 1.52) {
lcd.setCursor(0, 0);
lcd.print("Informations");
// Ajoutez ici le code pour afficher les informations nécessaires
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
current_page = 1;
delay(200); // Anti-bounce delay
}
}
previousButtonState = buttonState;
} else if (current_page == 1.52) {
lcd.setCursor(0, 0);
lcd.print("Informations");
// Code pour afficher les informations
if (buttonState == LOW && previousButtonState == HIGH) {
delay(50); // Débounce delay
if (buttonState == LOW) {
lcd.clear();
current_page = 1;
delay(200); // Anti-bounce delay
}
}
previousButtonState = buttonState;
}
// GESTION PROGRAMMATEUR
if (programmateur_enable == HIGH){
Serial.println("PROGRAMME ACTIVRE");
if (now.hour() >= startHour && now.hour() <= endHour) {
if ((now.hour() == startHour && now.minute() >= startMinute) || (now.hour() == endHour && now.minute() <= endMinute) || (now.hour() > startHour && now.hour() < endHour)) {
/*
if (chauffage_resistance_state == LOW) {
chauffage_resistance_state = HIGH;
}
if (pompe_state == LOW) {
pompe_state = HIGH;
}*/
}
}
}
if (pompe_activate_on_thirty_minutes == true) {
unsigned long currentMillis5 = millis();
if (currentMillis5 - chauffage_start_time >= chauffage_duration) {
pompe_chauffage_state = LOW;
pompe_activate_on_thirty_minutes = false;
Serial.println("Chauffage désactivé après 30 minutes");
}
}
}
void debut() {
lcd.setCursor(5,0);
lcd.print("BABOUILLE");
for (int i = 0; i < 16; i++) {
lcd.setCursor(i, 1);
lcd.print("#");
delay(100);
}
lcd.clear();
startTime = millis();
while (millis() - startTime < duration) {
lcd.setCursor(i,0);
lcd.write(0);
lcd.setCursor(i,1);
lcd.write(0);
lcd.setCursor(i+1,0);
lcd.write(1);
lcd.setCursor(i+1,1);
lcd.write(0);
lcd.setCursor(i-1,0);
lcd.write(1);
lcd.setCursor(i-1,1);
lcd.write(0);
lcd.setCursor(i+2,0);
lcd.write(2);
lcd.setCursor(i+2,1);
lcd.write(0);
lcd.setCursor(i-2,0);
lcd.write(2);
lcd.setCursor(i-2,1);
lcd.write(0);
lcd.setCursor(i+3,0);
lcd.write(3);
lcd.setCursor(i+3,1);
lcd.write(0);
lcd.setCursor(i-3,0);
lcd.write(3);
lcd.setCursor(i-3,1);
lcd.write(0);
lcd.setCursor(i+4,0);
lcd.write(4);
lcd.setCursor(i+4,1);
lcd.write(0);
lcd.setCursor(i-4,0);
lcd.write(4);
lcd.setCursor(i-4,1);
lcd.write(0);
lcd.setCursor(i+5,1);
lcd.write(1);
lcd.setCursor(i-5,1);
lcd.write(1);
lcd.setCursor(i+6,1);
lcd.write(2);
lcd.setCursor(i-6,1);
lcd.write(2);
lcd.setCursor(i+7,1);
lcd.write(3);
lcd.setCursor(i-7,1);
lcd.write(3);
delay(50);
lcd.clear();
i++;
if(i==21)
i=-7;
}
}
void open_programmateur() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Veuillez rentrer");
lcd.setCursor(0, 1);
lcd.print("une heure de ..");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(".. debut et de");
lcd.setCursor(0, 1);
lcd.print("fin");
delay(1200);
lcd.clear();
current_page = 1.42;
}
void write_symbole(int index) {
// Vérifier si l'index est valide
if (index < 0 || index >= sizeof(symbols) / sizeof(symbols[0])) {
lc.clearDisplay(0); // Effacer l'affichage si l'index est invalide
return;
}
// Obtenir le symbole correspondant
byte* symbol = symbols[index];
// Afficher le symbole sur le MAX7219
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, symbol[i]);
}
}
void displayFrame(byte frame[8]) {
for (int row = 0; row < 8; row++) {
lc.setRow(0, row, frame[row]);
}
}