Téléverser les fichiers vers "arduino_proto_threads/tp_serre"

Mise à jour pour UD4S 2026-10
This commit is contained in:
2026-10-24 04:20:07 +11:00
parent e2598c84e7
commit c076b20d7c
2 changed files with 64 additions and 57 deletions
@@ -43,6 +43,7 @@ void ttyWipe ( short lines ) {}
void ttySetIHM(long baud) {
Serial.begin(baud); // WIP check if baud in correct values ?
for (int i=0;i<10;i++) Serial.print("\n") ;
Serial.println(F("\nLog de " __FILE__ " du " __DATE__ " à " __TIME__));
}
void ttyPutStr(String txt) { Serial.println(txt);
}
+63 -57
View File
@@ -1,16 +1,25 @@
/* Si la température est < 15°C, un cycle de chauffe.
Si la température > 25 °C, le ventilateur tourne en proportion.
Si l’Humidité < 50%, un cycle arrosage.
Si l’Humidité >70 %, le ventilateur tourne en proportion
/* Si la température est < CMINT°C, un cycle de chauffe.
Si la température > CMAXT °C, le ventilateur tourne en proportion.
Si l’Humidité < CMINH %, un cycle arrosage.
Si l’Humidité >CMAXH %, le ventilateur tourne en proportion
*/
#define JAUNE 13 //
#define BLEU 12 //
#define ROUGE 11 //
#define VERTE 9 //
#define APVCC 2 //
#define APGND 6 //
#define AP_H A0 //
#define AP_T A1 //
#define CMINT 15 // consigne basse
#define CMAXT 25 // Consigne haute
#define CMINH 40 // consigne basse
#define CMAXH 50 // Consigne haute
#define TMIN 0 // echelle basse
#define TMAX 50 // echelle haute
#define HMIN 20 // echelle basse
#define HMAX 80 // echelle haute
#define MAXCYCLE 10 // nb max de cycles arrosage
#define JAUNE 13 // chauffe
#define BLEU 12 // arrosage
#define ROUGE 11 // ventilation
#define VERTE 9 // niveau
#define APVCC 2 // #define MAXCYCLE 500 // nb max de cycles+5V
#define APGND 6 // 0V
#define AP_H A2 // potard humidité
#define AP_T A1 // potard température
#define IHM
#include "serialTrace.h" // infos / trace to serial monitor
@@ -33,9 +42,9 @@ static int ptTemp(struct pt *pt, int repit) {
static unsigned long ttl = 0;
PT_BEGIN(pt);
while(1) {
ttl = millis() + repit ;
ttl = millis() + (repit*1000) ;
PT_WAIT_UNTIL(pt, millis() > ttl);
temp = acquis(AP_T, 0, 50); // pour ptHumi on a : humi = acquis(AP_T, 20, 80);
temp = acquis(AP_T, TMIN, TMAX);
ttyPutInt ("temp: ", temp);
}
PT_END(pt);
@@ -44,9 +53,9 @@ static int ptHumi(struct pt *pt, int repit) {
static unsigned long ttl = 0;
PT_BEGIN(pt);
while(1) {
ttl = millis() + repit;
ttl = millis() + (repit*1000);
PT_WAIT_UNTIL(pt, millis() > ttl);
humi = acquis(AP_H, 20, 80);
humi = acquis(AP_H, HMIN, HMAX);
ttyPutInt ("humi: ",humi);
}
PT_END(pt);
@@ -65,10 +74,11 @@ static int ptNiveau(struct pt *pt){
static int nb_old = 0; int ratio;
PT_BEGIN(pt);
while (!alarme) {
nb_old = nb_cycles;
ratio = map(nb_cycles, 0, 100, 254, 0);
ledPWM(VERTE, ratio);
PT_WAIT_UNTIL(pt, nb_cycles > nb_old ); // attente nouvel arrosage
ratio = map(nb_cycles, 0, MAXCYCLE, 254, 0);
ledPWM(VERTE, ratio);
ttyPutInt ("Niveau: ",ratio);
nb_old = nb_cycles;
}
PT_END(pt);
}
@@ -76,12 +86,12 @@ static int ptChauffe(struct pt *pt, int actif, int inactif ){
static unsigned long ttl = 0;
PT_BEGIN(pt);
while (1) {
PT_WAIT_UNTIL(pt, temp < 15);
PT_WAIT_UNTIL(pt, temp < CMINT);
digitalWrite(JAUNE, HIGH);
ttl = millis() + actif ;
ttl = millis() + (actif*1000) ;
PT_WAIT_UNTIL (pt, millis() > ttl);
digitalWrite(JAUNE, LOW);
ttl = millis() + inactif ;
ttl = millis() + (inactif*1000) ;
PT_WAIT_UNTIL (pt, millis() > ttl);
}
PT_END(pt);
@@ -90,32 +100,36 @@ static int ptEau(struct pt *pt, int actif, int inactif ) {
static unsigned long ttl = 0;
PT_BEGIN(pt);
while (!alarme) {
PT_WAIT_UNTIL(pt, humi < 50);
PT_WAIT_UNTIL(pt, humi < CMINH);
digitalWrite(BLEU, HIGH);
ttl = millis() + actif ;
nb_cycles++;
alarme = ( nb_cycles > 100);
ttl = millis() + (actif*1000) ;
PT_WAIT_UNTIL (pt, millis() > ttl);
digitalWrite(BLEU, LOW);
ttl = millis() + inactif ;
digitalWrite(BLEU, LOW);
nb_cycles++;
alarme = ( nb_cycles >= MAXCYCLE);
ttyPutInt ("Cycle: ",nb_cycles);
ttl = millis() + (inactif*1000) ;
PT_WAIT_UNTIL (pt, millis() > ttl);
}
PT_END(pt);
} // Eau
int vRatio(){
int t_ratio=0, h_ratio = 0, i = 0 ;
// On pilote la led sur la plage utile la plus petite
if (temp > CMAXT) t_ratio = map(temp, CMAXT, TMAX, 0,254);
if (humi > CMAXH) h_ratio = map(humi, CMAXH, HMAX, 0,254);
return max(t_ratio, h_ratio );
}
static int ptVenti(struct pt *pt) {
static int temp_old = 0, humi_old = 0; int t_ratio=0, h_ratio = 0, i ;
static unsigned long ttl = 0;
static int temp_old = 0, humi_old = 0;
PT_BEGIN(pt);
while (1) {
if (temp < 25 && humi < 70) digitalWrite(ROUGE, LOW);
PT_WAIT_UNTIL(pt, temp > 25 || humi > 70);
PT_WAIT_UNTIL(pt, temp > CMAXT || humi > CMAXH);
temp_old = temp;
humi_old = humi ;
if (temp > 25) t_ratio = map(temp, 0, 50, 0,254);
if (humi > 70) h_ratio = map(humi, 30, 100, 0,254);
i = max(t_ratio , h_ratio );
ledPWM(ROUGE, i) ;
PT_WAIT_UNTIL(pt, temp != temp_old || humi != humi_old );
humi_old = humi ;
ledPWM(ROUGE, vRatio()) ; // calcul du ration selon les mesures
PT_WAIT_UNTIL(pt, temp != temp_old || humi != humi_old );
ledPWM(ROUGE, vRatio()) ;
}
PT_END(pt);
} // Ventilateur
@@ -124,35 +138,27 @@ void initIO() {
pinMode(ROUGE, OUTPUT); analogWrite(ROUGE, 0);
pinMode(JAUNE, OUTPUT); pinMode(BLEU, OUTPUT);
digitalWrite(JAUNE, LOW); digitalWrite(BLEU, LOW) ;
pinMode(VERTE, OUTPUT); analogWrite(VERTE, 254); // at max
pinMode(VERTE, OUTPUT); analogWrite(VERTE, 254); // max
pinMode(APVCC, OUTPUT); pinMode(APGND, OUTPUT);
digitalWrite(APVCC, HIGH); digitalWrite(APGND, LOW);
}
void setup() {
int val;
initIO(); // Setup: set LEDs & pots
// static struct pt ptT, ptH, ptV, ptC, ptE, ptN, ptA ;
PT_INIT(&ptT); PT_INIT(&ptH); PT_INIT(&ptV); PT_INIT(&ptC);
PT_INIT(&ptE); PT_INIT(&ptN); PT_INIT(&ptA);
ttySetIHM(9600);
Serial.println(F("\nLog de " __FILE__ " du " __DATE__));
val=analogRead(1);
ttyPutInt("Raw Temp = ",val);
val=analogRead(0);
ttyPutInt("Raw humi = ",val);
temp = acquis(1, 0, 100);
ttyPutInt("Temp = ",temp);
humi = acquis(0, 0, 100);
ttyPutInt("Humi = ",humi);
temp = acquis(AP_T, TMIN, TMAX); // acquis potard T°
humi = acquis(AP_H, HMIN, HMAX); // acquis potard H%
}
void loop() {
ptTemp(&ptT,2000); // acquisition t° chaque 200ms
ptHumi(&ptH,4000); // acquisition % chaque 500ms
ptVenti(&ptV); // pilotage ventilation (LED Rouge)
ptChauffe(&ptC,5,10); // pilotage chauffage de 3s et inactivité de 3s (LED Jaune)
ptEau(&ptE,3,20); // pilotage arrosage de 3s et inactivité de 5s (LED Bleu)
ptNiveau(&ptN); // affichage niveau d’eau, PWM Verte de 254 à 0 (LED Verte)
ptAlarme(&ptA,500); // alarme réserve vide , clignote à 1Hz (LED Verte)
ptTemp(&ptT, 4); // acquisition t°chaque 5sec
ptHumi(&ptH, 6); // acquisition % chaque 10sec
ptVenti(&ptV); // ventilation
ptChauffe(&ptC,5,10); // chauffage 5s, inactivité 10s
ptEau(&ptE,3,10); // arrosage 3s, inactivité 40s
ptNiveau(&ptN); // niveau d’eau, PWM Verte
ptAlarme(&ptA,500); // réserve vide, clignote à 1Hz
}