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