-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel_Capteur_dhumidite_de_sol_liee_avec_ecran_LCD.ino
More file actions
139 lines (122 loc) · 3.13 KB
/
Copy pathModel_Capteur_dhumidite_de_sol_liee_avec_ecran_LCD.ino
File metadata and controls
139 lines (122 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adresse LCD (0x27 ou 0x3F)
int capteur = A0; // Broche du capteur
int valeur; // Valeur lue du capteur
int pourcentage; // Pourcentage d'humidité
unsigned long dernierChangement = 0; // Pour le changement d'affichage
int ecran = 0; // Quel écran afficher
// Messages de conseils
const char* conseils[] = {
"Arrose la plante!",
"C'est parfait :)",
"Arrosage OK!",
"Trop d'eau!!!"
};
void setup() {
Serial.begin(9600);
lcd.init(); // Démarrer l'écran
lcd.backlight(); // Allumer le rétro-éclairage
// Animation de démarrage
lcd.setCursor(0, 0);
lcd.print("Bonjour! :)");
for (int i = 0; i < 16; i++) {
lcd.setCursor(i, 1);
lcd.print(".");
delay(100);
}
delay(500);
lcd.clear();
}
void loop() {
// Lire la valeur du capteur
valeur = analogRead(capteur);
// Convertir en pourcentage (0-100%)
pourcentage = map(valeur, 1023, 0, 0, 100);
if (pourcentage < 0) pourcentage = 0;
if (pourcentage > 100) pourcentage = 100;
// Changer d'écran toutes les 3 secondes
if (millis() - dernierChangement > 3000) {
ecran = (ecran + 1) % 2;
dernierChangement = millis();
}
// Afficher les informations
afficherInfos();
delay(500); // Petite pause
}
void afficherInfos() {
lcd.clear();
// Première ligne : Humidité et animation
lcd.setCursor(0, 0);
lcd.print("H:");
lcd.print(pourcentage);
lcd.print("% ");
if (pourcentage < 30) {
lcd.print("SEC");
animationGoutte();
if (ecran == 1) {
lcd.setCursor(0, 1);
lcd.print(conseils[0]); // Arrose!
}
}
else if (pourcentage < 65) {
lcd.print("BON");
animationSmiley();
if (ecran == 1) {
lcd.setCursor(0, 1);
lcd.print(conseils[1]); // Parfait
}
}
else {
lcd.print("HUM");
animationPluie();
if (ecran == 1) {
lcd.setCursor(0, 1);
// Choisir le bon conseil
lcd.print(pourcentage > 85 ? conseils[3] : conseils[2]);
}
}
// Deuxième ligne : Barre de progression
if (ecran == 0) {
lcd.setCursor(0, 1);
int barres = map(pourcentage, 0, 100, 0, 16);
for (int i = 0; i < 16; i++) {
lcd.print(i < barres ? "|" : " ");
}
}
}
// Animation quand c'est trop sec
void animationGoutte() {
static int etape = 0;
lcd.setCursor(14, 0);
etape = (etape + 1) % 4;
switch(etape) {
case 0: lcd.print("v "); break;
case 1: lcd.print(" v"); break;
case 2: lcd.print(". "); break;
case 3: lcd.print(" ."); break;
}
}
// Animation quand c'est bon
void animationSmiley() {
static int etape = 0;
lcd.setCursor(14, 0);
etape = (etape + 1) % 3;
switch(etape) {
case 0: lcd.print(":)"); break;
case 1: lcd.print("8)"); break;
case 2: lcd.print(":]"); break;
}
}
// Animation quand trop humide
void animationPluie() {
static int etape = 0;
lcd.setCursor(14, 0);
etape = (etape + 1) % 4;
switch(etape) {
case 0: lcd.print("///"); break;
case 1: lcd.print("\\|\\"); break;
case 2: lcd.print("|||"); break;
case 3: lcd.print("..."); break;
}
}