Bonjour,
Je n'ai pas tout compris mais je vois que j'ai affaire aux bonnes personnes pour m'aider et apprendre.
Je vais, comme me l'a demandé J-M-L, faire un schéma de ma machine à état pour que vous compreniez bien ce que je veux faire.
Je poste ça dès que possible.
En attendant voici ce que j'ai fait et qui marche nickel... mais pas de bouton ni de machine à état, c'était avant que je complique en voulant ajouter un poussoir!
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // Déclaration type ecran
RTC_DS1307 RTC;
const byte pompe=4; // relais sur la pin 4 de l'arduino
const int ledPompeM=5; // Led Clignotement Pompe marche sur pin 5
const byte ledMarche=6; // Led Marche Système sur pin 6
int ledState = LOW;
// initialistaion millis pour clignotement LED
unsigned long previousMillis = 0;
const long interval = 1000;
// Fonction Pompe ON Forcé -----------------------------------------------------------------------
void PompeON_Force()
{
digitalWrite (pompe, LOW); // Pompe ON
//lcd.setCursor(10, 0);
//lcd.print(" FORCE");
//lcd.setCursor(11, 1);
//lcd.print(" ON ");
}
// Fonction Pompe OFF Forcé ----------------------------------------------------------------------
void PompeOFF_Force()
{
digitalWrite (pompe, HIGH); // Pompe ON
//lcd.setCursor(10, 0);
//lcd.print(" FORCE");
//lcd.setCursor(11, 1);
//lcd.print(" OFF ");
}
// Fonction Pompe OFF ----------------------------------------------------------------------
void PompeOFF()
{
digitalWrite (pompe, LOW); // Pompe OFF
lcd.setCursor(0,1);
lcd.print("---- MODE AUTO: ----");
lcd.setCursor(10,2);
lcd.print(" POMPE OFF");
}
// Fonction Pompe OFF ----------------------------------------------------------------------
void PompeON()
{
digitalWrite (pompe, HIGH); // Pompe ON
lcd.setCursor(0,1);
lcd.print("---- MODE AUTO: ----");
}
// Fonction Cligotement LED ----------------------------------------------------------------------
void Cligno_LED()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
lcd.setCursor(11,2);
lcd.print("POMPE ON ");
} else {
ledState = LOW;
lcd.setCursor(11,2);
lcd.print(" ");
}
digitalWrite(ledPompeM, ledState);
}
}
// Fonction LED OFF----------------------------------------------------------------------
void LED_OFF()
{
digitalWrite (ledPompeM, LOW);
}
void setup(){
pinMode(pompe, OUTPUT);
pinMode(ledPompeM, OUTPUT);
pinMode(ledMarche, OUTPUT);
digitalWrite (pompe, LOW);
digitalWrite (ledMarche, HIGH);
//Serial.begin(57600);
Wire.begin();
RTC.begin();
//Si RTC ne fonctionne pas
//if (! RTC.isrunning()) {
//Serial.println("RTC ne fonctionne pas !");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(__DATE__, __TIME__));
//}
//Initialisation du LCD---------------------------------------------
lcd.init();
lcd.cursor_on();
lcd.blink_on();
lcd.backlight();
lcd.setCursor(0, 0);
}
void loop(){
//Affichage de l'heure
DateTime now = RTC.now();
//Affichage HEURE ------------------------------------------------------
lcd.setCursor(12, 0);
lcd.print(now.hour());
lcd.print(":");
if (now.minute() < 10) {
lcd.print("0");
}
lcd.print(now.minute());
lcd.print(":");
if (now.second() < 10) {
lcd.print("0");
}
lcd.print(now.second());
//Affichage DATE ------------------------------------------------------
lcd.setCursor(0, 0);
if (now.day() < 10) {
lcd.print("0");
}
lcd.print(now.day());
lcd.print(" ");
switch (now.month()) {
case 1:
lcd.print("JAN");
break;
......
case 12:
lcd.print("DEC");
break;
}
lcd.print(" ");
lcd.print(now.year());
lcd.cursor_off();
lcd.blink_off();
if(now.hour() == 9 && now.minute() <= 30) {
PompeON();
Cligno_LED();
lcd.setCursor(0,2);
lcd.print(" 9h->9h30 ");
}
if(now.hour() == 9 && now.minute() > 30) {
PompeOFF();
LED_OFF();
lcd.setCursor(0,2);
lcd.print("9h30->10h ");
}
.......
if(now.hour() == 17 || now.hour() == 18 || now.hour() == 19 || now.hour() == 20) {
PompeON();
Cligno_LED();
lcd.setCursor(0,2);
lcd.print(" 17h->21h ");
}
if(now.hour() == 21 || now.hour() == 22 || now.hour() == 23 || now.hour() == 00 || now.hour() == 1 || now.hour() == 2 || now.hour() == 3 || now.hour() == 4 || now.hour() == 5 || now.hour() == 6 || now.hour() == 7 || now.hour() == 8) {
PompeOFF();
LED_OFF();
lcd.setCursor(0,2);
lcd.print(" 21h->9h ");
}
//delay(900);
}
J'ai inclus la Lib Wire car je vais aussi gérer 2 sondes de T°... ça je sais faire car déjà fait dans un autre projet.