From 35b967f95ed1e1bd1913ead16d785772d11b017b Mon Sep 17 00:00:00 2001 From: Mamadou diallo Date: Fri, 13 Jul 2018 16:36:55 +0000 Subject: [PATCH] ajout de l'ecran et de l'encodeur --- Khomi-auto-3.ino | 88 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/Khomi-auto-3.ino b/Khomi-auto-3.ino index e3904e3..ec12dfd 100644 --- a/Khomi-auto-3.ino +++ b/Khomi-auto-3.ino @@ -14,6 +14,15 @@ //Déclaration des variables du programme int valeur_hum_sol = 0; // on stocke les valeurs lu par le capteur d'humidité sol +int heure = 0; +int minut = 0; + +int Switch = 10; //switch boutton poussoir encoder +byte portA = 11; //encoder invertion fritzing 6 +byte portB = 9; // encoder +byte etat = 0; +bool etat_switch = false; + RTC_DS1307 rtc; char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; @@ -29,12 +38,22 @@ void setup () lcd.begin (16, 2); // for 16 x 2 LCD module lcd.setBacklightPin(3, POSITIVE); lcd.setBacklight(HIGH); + lcd.clear(); + lcd.setCursor(3, 0); + lcd.print("KHomiAuto"); + delay(1000); + lcd.clear(); pinMode(capteur_hum_sol, INPUT); pinMode(capteur_reservoir, INPUT); + pinMode(portA, INPUT); + pinMode(portB, INPUT); + pinMode(Switch, INPUT_PULLUP); pinMode(pin_hum_sol, OUTPUT); pinMode(pompe, OUTPUT); pinMode(electrovanne, OUTPUT); + attachInterrupt(0, control, CHANGE); + attachInterrupt(1, control, CHANGE); ////////////////////////////////////// configuration de l'horloge ////////////////////////////////////// if (! rtc.begin()) @@ -59,7 +78,10 @@ void loop () // on lit l'heure sur le rtc DateTime now = rtc.now(); //on lance le debug pour verifier si il ya pas de probleme - Debug(); + //Debug(); + control(); + + affiche_lcd(); //on test si il est heure d'arroser @@ -110,21 +132,64 @@ void arroser () { } } -////////////////////////////////////// Débug ////////////////////////////////////// +void control() { + etat = etat << 1 | digitalRead(portA); + etat = etat << 1 | digitalRead(portB); + + byte etat_test = (etat | B11110000) - B11110000;//test des 4 bits de poids faible + //Serial.println(etat_test,BIN);//débug : visualisation de la séquence + + + //bouton poussoir + if (digitalRead(Switch) == false) + { + etat_switch = !etat_switch; + } + + if ( etat_test == B0111 ) + { + heure++; + } + else if ( etat_test == B1011 ) + { + heure--; + + if ( heure < 0) + { + heure = 00; + } + } + else if (heure == 25) + { + heure = 00; + } + else if (minut == 61) + { + minut == 00; + } + +} + +////////////////////////////////////// fonction affichage ////////////////////////////////////// void affiche_lcd() { DateTime now = rtc.now(); - lcd.home (); // set cursor to 0,0 - lcd.print(now.hour()); - lcd.print(':'); - lcd.print(now.minute()); - lcd.print(':'); - lcd.print(now.second()); - lcd.print(" "); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("H="); + lcd.print(heure); + lcd.setCursor(7, 0); + lcd.print("M="); + lcd.print(minut); + + lcd.setCursor(2, 1); + lcd.println(etat_switch); } +////////////////////////////////////// Débug ////////////////////////////////////// + void Debug() { DateTime now = rtc.now(); @@ -145,7 +210,10 @@ void Debug() Serial.print(now.year()); Serial.print(" valeur humidite sol "); - Serial.println(valeur_hum_sol); + Serial.print(valeur_hum_sol); + + Serial.print(" heure "); + Serial.println(heure); delay(1000); } -- GitLab