Bonjour,
J'ai fais un menu pour le LCD me permettant de choisir un paramètre.
Je souhaite aussi faire un menu permettant de choisir mon programme.
Actuellement programme() est le seul mais à terme il y aura programme 1(), 2(), 3()...etc
Dans le code suivant je n'ai qu'un programme :
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int entree_menus = 44;
int commande_monter = 50;
int commande_retour = 51;
int securite = 53;
int contact_moteur = 22;
int electro_vanne_1 = 24;
int tempo_retour_automatique;
enum etat : byte {
BUTTON_NONE,
BUTTON_UP,
BUTTON_DOWN,
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_SELECT,
PROGRAMME_EN_ATTENTE,
PROGRAMME_MONTEE,
PROGRAMME_ARRET_MONTEE,
PROGRAMME_SECURITE,
PROGRAMME_RETOUR_AUTO,
REGLAGES_EN_ATTENTE,
MENU_TEMPORISATION,
REGLAGES_RETOUR
};
etat etat_programme = PROGRAMME_EN_ATTENTE;
etat etat_reglages = REGLAGES_EN_ATTENTE;
void setup() {
lcd.begin(16, 2);
EEPROM.get(10,tempo_retour_automatique);
lcd.setCursor(0, 0);
lcd.write("Digital Dock");
delay (1000);
lcd.setCursor(0, 1);
lcd.write("v1.11");
delay(5000);
pinMode(entree_menus, INPUT);
pinMode(commande_monter, INPUT);
pinMode(commande_retour, INPUT);
pinMode(securite, INPUT);
pinMode(contact_moteur, OUTPUT);
pinMode(electro_vanne_1, OUTPUT);
lcd.clear();
}
byte getPressedButton() {
int value = analogRead(A0);
if (value < 50)
return BUTTON_RIGHT;
else if (value < 250)
return BUTTON_UP;
else if (value < 410)
return BUTTON_DOWN;
else if (value < 550)
return BUTTON_LEFT;
else if (value < 850)
return BUTTON_SELECT;
else
return BUTTON_NONE;
}
void loop()
{
if (digitalRead(entree_menus) == HIGH){
reglages();
}
else{
programme();
}
}
void programme()
{
static unsigned long lancement_retour;
switch (etat_programme) {
case PROGRAMME_EN_ATTENTE:
digitalWrite(electro_vanne_1,HIGH);
if ((digitalRead(securite) == HIGH)&&(digitalRead(commande_monter) == HIGH)) {
lcd.setCursor(0, 0);
lcd.print("MONTER ");
lcd.setCursor(0, 1);
lcd.print(" ");
digitalWrite(contact_moteur,HIGH);
etat_programme = PROGRAMME_MONTEE;
}
if (digitalRead(securite) == LOW){
lcd.setCursor(0, 0);
lcd.print("SECURITES ");
lcd.setCursor(0, 1);
lcd.print("P1 ");
digitalWrite(contact_moteur,LOW);
digitalWrite(electro_vanne_1,LOW);
etat_programme = PROGRAMME_SECURITE;
}
if ((digitalRead(securite) == HIGH)&&(digitalRead(commande_retour) == HIGH)){
lcd.setCursor(0, 0);
lcd.print("RETOUR ");
lcd.setCursor(0, 1);
lcd.print("AUTOMATIQUE ");
digitalWrite(contact_moteur,HIGH);
lancement_retour = millis();
etat_programme = PROGRAMME_RETOUR_AUTO;
}
break;
case PROGRAMME_MONTEE:
if ((digitalRead(securite) == HIGH)&&(digitalRead(commande_monter) == HIGH)){
digitalWrite(contact_moteur,HIGH);
etat_programme = PROGRAMME_ARRET_MONTEE;
}
break;
case PROGRAMME_ARRET_MONTEE:
if ((digitalRead(securite) == HIGH)&&(digitalRead(commande_monter) == LOW)) {
lcd.clear();
digitalWrite(contact_moteur,LOW);
etat_programme = PROGRAMME_EN_ATTENTE;
}
break;
case PROGRAMME_SECURITE:
if (digitalRead(securite) == HIGH) {
lcd.clear();
delay (1000);
etat_programme = PROGRAMME_EN_ATTENTE;
}
break;
case PROGRAMME_RETOUR_AUTO:
if (digitalRead(commande_retour) == HIGH) {
digitalWrite(contact_moteur,HIGH);
etat_programme = PROGRAMME_EN_ATTENTE;
}
if (digitalRead(securite) == LOW){
lcd.setCursor(0, 0);
lcd.print("SECURITES ");
lcd.setCursor(0, 1);
lcd.print("P1 ");
digitalWrite(contact_moteur,LOW);
digitalWrite(electro_vanne_1,LOW);
etat_programme = PROGRAMME_SECURITE;
}
else {
if (millis() - lancement_retour >= tempo_retour_automatique) {
digitalWrite(contact_moteur,LOW);
lcd.clear();
etat_programme = PROGRAMME_EN_ATTENTE;
}
}
break;
}
}
void reglages()
{
switch (etat_reglages) {
case REGLAGES_EN_ATTENTE:
if (digitalRead(entree_menus) == LOW){
delay (500);
programme();
}
else {
digitalWrite(contact_moteur,LOW);
digitalWrite(electro_vanne_1,LOW);
etat_reglages = MENU_TEMPORISATION;
}
break;
case MENU_TEMPORISATION:
lcd.setCursor(0, 0);
lcd.print("TEMPORISATION ");
lcd.setCursor(0, 1);
lcd.print("RETOUR AUTO ");
if (getPressedButton() == BUTTON_RIGHT) {
lcd.clear();
etat_reglages = REGLAGES_RETOUR;
}
if (digitalRead(entree_menus) == LOW){
lcd.clear();
etat_reglages = REGLAGES_EN_ATTENTE;
delay (200);
}
break;
case REGLAGES_RETOUR:
lcd.setCursor(0, 0);
lcd.print("TEMPORISATION ");
lcd.setCursor(15, 1);
lcd.print("S");
lcd.setCursor(12, 1);
lcd.print(tempo_retour_automatique/1000);
if (getPressedButton() == BUTTON_UP) {
delay (100);
tempo_retour_automatique = tempo_retour_automatique + 1000;
tempo_retour_automatique = constrain(tempo_retour_automatique,1000,30000);
lcd.clear();
etat_reglages = REGLAGES_RETOUR;
}
if (getPressedButton() == BUTTON_DOWN) {
delay (100);
tempo_retour_automatique = tempo_retour_automatique - 1000;
tempo_retour_automatique = constrain(tempo_retour_automatique,1000,30000);
lcd.clear();
etat_reglages = REGLAGES_RETOUR;
}
if (getPressedButton() == BUTTON_LEFT) {
EEPROM.put(10,tempo_retour_automatique);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" REGLAGES ");
lcd.setCursor(0,1);
lcd.print(" ENREGISTRES ");
delay(1500);
etat_reglages = MENU_TEMPORISATION;
}
if (digitalRead(entree_menus) == LOW){
lcd.clear();
etat_reglages = REGLAGES_EN_ATTENTE;
}
break;
}
}