/*
*/
// =============================================================================================================
// --- Bibliotecas Auxiliares ---
//#include <LiquidCrystal.h>//
//#include <LiquidCrystal_I2C.h>
// Importar las librerias LiquidCrystal I2C y Wire
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Iniciar la libreria
LiquidCrystal_I2C lcd(0x27, 16, 2);
// =============================================================================================================
// --- Mapeamento de Hardware --- ARDUINO
#define bt_r 14 //botão direita
#define bt_l 15 //botão esquerda
#define bt_e 16 //botão enter
#define bt_b 17 //botão voltar
#define motor_M1_ABRIR_VALVULAS 7 //
#define motor_M2_CEPILLO 6 //
#define motor_M3_BOMBA 5 //
#define electro_VALVULA 4 //
#define S1_FC_ABIERTO 3 //
#define S2_FC_CERRADO 2 //
#define RESET_boton 0 // para limpiar flag de estado de boton
char sensor_S1_FC_ABIERTO = RESET_boton ;
char sensor_S2_FC_CERRADO = RESET_boton ;
bool FLAG_ERROR_S1_FC_ABIERTO = false ; // $$$
#define PULSADA 1 //
#define NO_PULSADA 0 //
#define RESET_boton 0 // para limpiar flag de estado de boton
// GLOBALES
char boton_DERECHA = RESET_boton ;
char boton_IZQUIERDA = RESET_boton ;
char boton_ENTER = RESET_boton ;
char boton_BACK = RESET_boton ; // buffer de botones
// =============================================================================================================
// --- Constantes e Objetos ---
#define menu_max 5 //número máximo de menus existentes
//const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
//LiquidCrystal_I2C lcd(rs, en, d4, d5, d6, d7);
// ========================== TIMER MARCHA ON FILTER ======================================
int tiempoMARCHA_FILTRO = 5000 ; // tiempo para que el led se encienda 1000 ms lili seg
bool tempSTATUS_TMRON = false ; //estado del temporizador, 1= activo 0= inactivo
unsigned long tiempoAnteriorTIMER_ON = 0 ; //guarda tiempo de referencia para comparar
bool FLAG_MARCHA_OK = false ;
bool FLAG_CONFIRMACION_MARCHA = false ;
// =============================================================================================================
// --- Prototipo de las Funçiones ---
// void keyboard(); no se usa
void navegacionMenu();
void control_botonS() ; // para registro por puerto Serie
void menu1();
void menu2();
void menu3();
void menu4();
void menu5();
void config_SICLO_MARCHA();
void config_TIEMPO_SICLO_ENTRE_MARCHAS() ;
void config_MODO_SICLO_FILTRO();
void config_MODO_LOCAL_REMOTO_FILTRO();
void control_LOCAL_MANUAL_FILTRO();
void ejecutarMARCHA_FILTRO() ;
void ejecutarDETENCION_FILTRO() ;
// =============================================================================================================
// --- Variables Globales ---
//
// =============================================================================================================
int menu_num = 1, sub_menu = 1, submenu1 = 1 , submenu2 = 1 , submenu3 =1 , submenu4 =1 , submenu5 = 1 ;
int tiempo_SICLO_ON_FILTRO = 10 ; // tiempo en segundos
int tiempo_SICLO_OFF_FILTRO = 10 ;
#define HABILITADO 1 //
#define DESABILITADO 0 //
int FLAG_ENABLE_MENU = HABILITADO ;
#define AUTOMATICO 1 //
#define MANUAL 0 //
int MODO_FILTRO = MANUAL ; // realizar etiquetas
#define LOCAL 1 //
#define REMOTO 0 //
int MODO_FILTRO_LR = LOCAL ; // realizar etiquetas
// int FLAG_INCREMENTAR = 0 , FLAG_DECREMENTAR = 0 ; // no implementados
// =========================================================================================
// --- Configuraçiones Iniciales ---
void setup()
{
lcd.backlight();
pinMode(bt_r, INPUT_PULLUP);
pinMode(bt_l, INPUT_PULLUP);
pinMode(bt_e, INPUT_PULLUP);
pinMode(bt_b, INPUT_PULLUP);
pinMode(S1_FC_ABIERTO , INPUT_PULLUP); // GPIESP32 25 //
pinMode(S2_FC_CERRADO , INPUT_PULLUP); // GPIESP32 26 //
/* ESP32
#define pinMode(motor_M1_ABRIR_VALVULAS , OUTPUT); // 4 //
#define pinMode(motor_M2_CEPILLO , OUTPUT); // 0 //
#define pinMode(motor_M3_BOMBA , OUTPUT); // 2 //
#define pinMode(electro_VALVULA , OUTPUT); // 15 //
#define pinMode(S1_FC_ABIERTO , OUTPUT); // 25 //
#define pinMode(S2_FC_CERRADO , OUTPUT); // 26 //
*/
/* // ARDUINO
#define motor_M1_ABRIR_VALVULAS 7 //
#define motor_M2_CEPILLO 6 //
#define motor_M3_BOMBA 5 //
#define electro_VALVULA 4 //
#define S1_FC_ABIERTO 3 //
#define S2_FC_CERRADO 2 //
*/
pinMode(motor_M1_ABRIR_VALVULAS , OUTPUT); // 7 //
pinMode(motor_M2_CEPILLO , OUTPUT); // 6 //
pinMode(motor_M3_BOMBA , OUTPUT); // 5 //
pinMode(electro_VALVULA , OUTPUT); // 4 //
//pinMode(S1_FC_ABIERTO , OUTPUT); // 03 //
//pinMode(S2_FC_CERRADO , OUTPUT); // 02 //
lcd.begin(16, 2);
Serial.begin(9600);
} //end setup
// =============================================================================================================
// --- Configuraçiones Iniciales ---
void loop()
{
// keyboard();
navegacionMenu() ;
switch(menu_num)
{
case 1: menu1(); break;
case 2: menu2(); break;
case 3: menu3(); break;
case 4: menu4(); break;
case 5: menu5(); break;
} // fin switch
// depuracion
if ( FLAG_MARCHA_OK == true)
{
ejecutarMARCHA_FILTRO() ; // ejecutar desde menu 5 por flag FLAG_MARCHA_OK pulsando ENTER
// flag se resetea al fin de esta subrutina
}
} //fin loop
// =============================================================================================================
// --- Desenvolvimento das Funções ---
void navegacionMenu()
{
//if (menu_num <= 0 ) menu_num = 1 ;
//if (menu_num > menu_max) menu_num = 1 ;
//if (sub_menu <= 0 ) sub_menu = 1 ;
//if (sub_menu > menu_max) sub_menu = 1 ;
//if (submenu1 <= 0 ) submenu1 = 1 ;
//if (submenu1 > 3 ) submenu1 = 1 ; // max submenu1 !!
// boton_DERECHA =0, boton_IZQUIERDA = 0; boton_ENTER = 0, boton_BACK =0;
boton_DERECHA = !digitalRead(bt_r) ;
if((boton_DERECHA == PULSADA ) && sub_menu == 1 )
{ control_botonS() ;
boton_DERECHA = RESET_boton ;
delay (350);
control_botonS() ;
if(menu_num <= menu_max) menu_num += 1;
if(menu_num > menu_max) menu_num = 1;
} //end bt_r
boton_IZQUIERDA = !digitalRead(bt_l) ; // lectura de boton IZQ
if( ( boton_IZQUIERDA == PULSADA ) && sub_menu == 1 )
{ control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ;
if(menu_num > 0) menu_num -= 1;
if(menu_num <= 0) menu_num = menu_max;
control_botonS() ;
} //end bt_l
boton_ENTER = !digitalRead(bt_e) ; // lectura de boton ENTER
if( boton_ENTER == PULSADA &&
FLAG_ENABLE_MENU == HABILITADO )
{ control_botonS() ;
boton_ENTER = RESET_boton;
delay (350) ;
if(sub_menu <= 2 ) sub_menu += 1;
if(sub_menu > 5 ) sub_menu = 1; // max sub_menu opciones
} //end bt_e
boton_BACK = !digitalRead(bt_b) ; // lectura de boton BACK
if( boton_BACK == PULSADA )
{ control_botonS() ; // contro por puerto serie de los flags estados de botones
boton_BACK = RESET_boton ;
delay (350) ;
if(sub_menu > 0) sub_menu -= 1 ;
if(sub_menu <= 0) sub_menu = 1 ;
} //end bt_b
if ( sub_menu > 1 ) FLAG_ENABLE_MENU = DESABILITADO ; // si se encuentra en un submenu de ejecucion
if ( sub_menu <= 1) FLAG_ENABLE_MENU = HABILITADO ; // desabilitar navegacion de menu principal
} //end navegacionMenu
void menu1()
{
switch(sub_menu)
{
case 1:
lcd.setCursor(0,0);
lcd.print("CONFIG Tiempo >");
lcd.setCursor(0,1);
lcd.print(" SICLO MARCHA ");
break;
case 2:
config_SICLO_MARCHA();
break;
}
} //end menu1
void menu2()
{
switch(sub_menu)
{
case 1:
lcd.setCursor(0,0);
lcd.print("CONFIG Tiempo >");
lcd.setCursor(0,1);
lcd.print("ENTRE SICLOS ");
break;
case 2:
lcd.setCursor(0,0);
// lcd.print("TiempoSICLO OFF");
lcd.setCursor(0,1);
// lcd.print(" 10 MIN ");
config_TIEMPO_SICLO_ENTRE_MARCHAS();
break;
}
} //end menu2
void menu3()
{
switch(sub_menu)
{
case 1:
lcd.setCursor(0,0);
lcd.print("< CONFIG MODO >");
lcd.setCursor(0,1);
lcd.print(" TRABAJO FILTRO ");
break;
case 2:
lcd.setCursor(0,0);
//lcd.print(" Ohmimetro ");
lcd.setCursor(0,1);
//lcd.print(" 100 Ohms ");
config_MODO_SICLO_FILTRO();
break;
}
} //end menu3
void menu4()
{
switch(sub_menu)
{
case 1:
lcd.setCursor(0,0);
lcd.print("< CONFIG LOC/REM"); // CONFIGURACION LOCAL REMOTO
lcd.setCursor(0,1);
lcd.print(" ");
break;
case 2:
lcd.setCursor(0,0);
//lcd.print(" Wattimetro ");
lcd.setCursor(0,1);
//lcd.print(" 55 Watts ");
config_MODO_LOCAL_REMOTO_FILTRO();
break;
}
} //end menu4
void menu5()
{
switch(sub_menu)
{
case 1:
lcd.setCursor(0,0);
lcd.print("< CONTROL L/M"); // CONFIGURACION LOCAL REMOTO
lcd.setCursor(0,1);
lcd.print(" ");
break;
case 2:
lcd.setCursor(0,0);
//lcd.print(" Wattimetro ");
lcd.setCursor(0,1);
//lcd.print(" 55 Watts ");
control_LOCAL_MANUAL_FILTRO();
break;
}
} //end menu4
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// =======================================================================
// --- Direccionamiento de Hardware Teclado ---
/*
#define PULSADA 1 //
#define NO_PULSADA 0 //
#define RESET_boton 0 // para limpiar flag de estado de boton
// GLOBALES
char boton_DERECHA = RESET_boton ;
char boton_IZQUIERDA = RESET_boton ;
char boton_ENTER = RESET_boton ;
char boton_BACK = RESET_boton ; // buffer de botones
*/
/* ###############################################################
// =======================================================================
// se debe implementar sin esta rutina
// =======================================================================
// --- Desarrollo de Funcion Teclado keyboard() ---
void keyboard()
{
// static char boton_DERECHA =0; boton_IZQUIERDA = 0; boton_ENTER = 0; boton_BACK =0; // buffer de botones
if(!digitalRead(bt_r)) boton_DERECHA = PULSADA ;
if(!digitalRead(bt_l)) boton_IZQUIERDA = PULSADA ;
if(!digitalRead(bt_e)) boton_ENTER = PULSADA ;
if(!digitalRead(bt_b)) boton_BACK = PULSADA ;
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
} // fin keyboard
// ###############################################################
*/
void config_SICLO_MARCHA()
{
lcd.setCursor(0,0);
lcd.print("Tiempo SICLO ON ");
switch(submenu1)
{
case 1:
lcd.setCursor(0,1);
lcd.print("INCREMENTAR S >");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
tiempo_SICLO_ON_FILTRO += 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// FLAG_ENABLE_MENU = DESABILITADO ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_BACK = !digitalRead(bt_e) ;
if ( boton_BACK == PULSADA) {
control_botonS() ;
boton_BACK = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ; submenu1 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ; submenu1 = 3;}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("< DECREMENTAR >");
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA) {
tiempo_SICLO_ON_FILTRO -= 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
// FLAG_DECREMENTAR = 1;
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350); submenu1 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton; delay (350); submenu1 --;}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< FINALIZAR ");
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350); submenu1 -- ;
}
break;
} // fin switch submenu1
} // finsubrutina funcion SICLO TIME FILTRO
// config_TIEMPO_SICLO_ENTRE_MARCHAS();
void config_TIEMPO_SICLO_ENTRE_MARCHAS()
{
lcd.setCursor(0,0);
lcd.print("TiempoSICLO OFF");
switch(submenu2)
{
case 1:
lcd.setCursor(0,1);
lcd.print(" INCREMENTAR >");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
tiempo_SICLO_OFF_FILTRO += 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// FLAG_ENABLE_MENU = DESABILITADO ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_BACK = !digitalRead(bt_e) ;
if ( boton_BACK == PULSADA) {
control_botonS() ;
boton_BACK = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ; submenu2 =2;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ; submenu2 =3;}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("< DECREMENTAR >");
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA) {
tiempo_SICLO_OFF_FILTRO -= 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
//FLAG_DECREMENTAR = 1;
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350); submenu1 =3 ;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton; delay (350); submenu2 = 1;}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< FINALIZAR ");
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350); submenu2 =2 ;
}
break;
} //end switch
//
} //end SICLO TIME OFF FILTRO
void config_MODO_SICLO_FILTRO()
{
lcd.setCursor(0,0);
lcd.print(" MODO FILTRO ");
switch(submenu3)
{
case 1:
lcd.setCursor(0,1);
lcd.print(" ACTIVAR MANUAL >");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
MODO_FILTRO = MANUAL ; // realizar etiquetas
control_botonS() ;
boton_ENTER = RESET_boton ;
// FLAG_ENABLE_MENU = DESABILITADO ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_BACK = !digitalRead(bt_e) ;
if ( boton_BACK == PULSADA) {
control_botonS() ;
boton_BACK = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ; submenu3 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ; submenu3 = 3;}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("< ACT AUTOMATIC >");
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA) {
MODO_FILTRO = AUTOMATICO ; // realizar etiquetas
control_botonS() ;
boton_ENTER = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
//FLAG_DECREMENTAR = 1;
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350); submenu3 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton; delay (350); submenu3 --;}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< MODO ACTUAL "); // implementar visualizacion de modo actual de trabajo
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350); submenu3 -- ;
}
break;
} //end switch
}
void config_MODO_LOCAL_REMOTO_FILTRO()
{
lcd.setCursor(0,0);
lcd.print("MOD LOCAL/REMOTO");
switch(submenu4)
{
case 1:
lcd.setCursor(0,1);
lcd.print(" ACTIVAR LOCAL >");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
MODO_FILTRO_LR = LOCAL ; // realizar etiquetas
control_botonS() ;
boton_ENTER = RESET_boton ;
// FLAG_ENABLE_MENU = DESABILITADO ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_BACK = !digitalRead(bt_e) ;
if ( boton_BACK == PULSADA) {
control_botonS() ;
boton_BACK = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ; submenu4 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ; submenu4 = 3;}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("< ACTIVR REMOTO >"); // ACTIVAR MODO REMOTO
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA) {
MODO_FILTRO_LR = REMOTO ; // realizar etiquetas
control_botonS() ;
boton_ENTER = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
//FLAG_DECREMENTAR = 1;
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350); submenu4 ++;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton; delay (350); submenu4 --;}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< MOD ACTUAL L/R"); // implementar visualizacion de modo actual de trabajo
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350); submenu4 -- ;
}
break;
} //end switch
}
// control_LOCAL_MANUAL_FILTRO
void control_LOCAL_MANUAL_FILTRO()
{
lcd.setCursor(0,0);
lcd.print("CONTROL LOC/MAN");
switch(submenu5)
{
case 1:
lcd.setCursor(0,1);
lcd.print("ARRANQUE FILTRO");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
boton_ENTER = RESET_boton ;
// SUBRUTINA ARRANQUE
//ejecutar subrutina submenu 5.1
// INICIALIZO SUBRUTINA ARRANQUE
tiempoAnteriorTIMER_ON = millis(); //guarda el tiempo actual como referencia
tempSTATUS_TMRON = true ; //indica que esta activo el temporizador
// ARDUINO LOG + !!!!
digitalWrite(motor_M1_ABRIR_VALVULAS, HIGH) ; // ON motor_M1_ABRIR_VALVULAS prender ACTIVAR POR LOW
Serial.print(F(" Time Arranque FILTRO: ==================>" )) ;
Serial.println( tiempoAnteriorTIMER_ON );
// SUBRUTINA ARRANQUE
FLAG_MARCHA_OK = true ; // habilitar ejecucion en MAIN == loop ()
// ejecutarMARCHA_FILTRO() ;
control_botonS() ;
boton_ENTER = RESET_boton ;
delay (350) ;
// ejecutarARRANQUE_LOCAL_MANUAL();
// control_botonS() ;
// delay (350) ;
// //control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ;
submenu5 =2;
}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ;
submenu5 = 3;
}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("<DETENER FILTRO>");
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA)
{
control_botonS() ;
boton_ENTER = RESET_boton ;
// DETENER FILTRO
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350);
submenu5 = 3;
}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350);
submenu5 = 1;
}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< FINALIZAR ");
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350);
submenu5 =2 ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350);
submenu5 = 1;
}
break;
} // fin switch
} // fin MENU 5 CONTROL MARCHA LOCAL MANUAL
// opcion case 1 de menu 5
//*******************************************************************
void ejecutarARRANQUE_LOCAL_MANUAL()
{
//lcd.setCursor(0,0);
//lcd.print("ARRANCANDO FLTR");
// digitalWrite(LATCH_PIN, LOW);
// digitalWrite(motor_M1_ABRIR_VALVULAS , HIGH); // 4 //
// digitalWrite(motor_M2_CEPILLO , HIGH); // 0 //
// digitalWrite(motor_M3_BOMBA , HIGH); // 2 //
// digitalWrite(electro_VALVULA , HIGH); // 15 //
// digitalWrite(S1_FC_ABIERTO , HIGH); // 25 //
// digitalWrite(S2_FC_CERRADO , HIGH); // 26 //
/*
lcd.setCursor(0,1);
lcd.print(" INCREMENTAR >");
boton_ENTER = !digitalRead(bt_e) ;
if ( boton_ENTER == PULSADA) {
tiempo_SICLO_OFF_FILTRO += 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// FLAG_ENABLE_MENU = DESABILITADO ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_BACK = !digitalRead(bt_e) ;
if ( boton_BACK == PULSADA) {
control_botonS() ;
boton_BACK = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
delay (350) ;
//control_botonS() ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if( boton_DERECHA == PULSADA ) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350) ; submenu2 =2;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if( boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton;
delay (350) ; submenu2 =3;}
break;
case 2:
lcd.setCursor(0,1);
lcd.print("< DECREMENTAR >");
boton_ENTER = !digitalRead(bt_e) ;
if( boton_ENTER == PULSADA) {
tiempo_SICLO_OFF_FILTRO -= 1 ;
control_botonS() ;
boton_ENTER = RESET_boton ;
// guardar en buffer ROM --> tiempo_SICLO_ON_FILTRO
// controles de limites
//FLAG_DECREMENTAR = 1;
delay (350) ;
}
boton_DERECHA = !digitalRead(bt_r) ;
if(boton_DERECHA == PULSADA) {
control_botonS() ;
boton_DERECHA = RESET_boton;
delay (350); submenu1 =3 ;}
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton; delay (350); submenu2 = 1;}
break;
case 3:
lcd.setCursor(0,1);
lcd.print("< FINALIZAR ");
boton_IZQUIERDA = !digitalRead(bt_l) ;
if(boton_IZQUIERDA == PULSADA ) {
control_botonS() ;
boton_IZQUIERDA = RESET_boton ;
delay (350); submenu2 =2 ;
}
break;
} //end switch
*/
}
//*************************************************************
void ejecutarMARCHA_FILTRO()
{
if( (( millis()- tiempoAnteriorTIMER_ON ) >= (tiempo_SICLO_ON_FILTRO*1000) ) && (tempSTATUS_TMRON == true) )
{
//si ha transcurrido el tiempoMARCHA_FILTRO programado EJECUTAR FIN
//digitalWrite( motor_M1_ABRIR_VALVULAS , HIGH ) ; // apago filtro
FLAG_MARCHA_OK = false ; // una marcha por vez .. fin de marcha
tempSTATUS_TMRON = false ; //y desactivo el temporizador
Serial.print(F(" Time Detencion FILTRO: ===================> " ));
Serial.println( millis() );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ; //
}
// #define S1_FC_ABIERTO 3 //
// #define S2_FC_CERRADO 2 //
// **$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ en revicion 6 mayo $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
sensor_S1_FC_ABIERTO = !digitalRead(S1_FC_ABIERTO) ; // se guarda estado de S1
if( sensor_S1_FC_ABIERTO == PULSADA ) { // en logica ++
Serial.print(F(" Time Detencion ACTIVADO sensor_S1_FC_ABIERTO : ===================> " ) );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ; //
// FLAG_CONTROL_S1_FC_ABIERTO = true ; // OK pulsado una vez en el siclo de TIMER
control_botonS() ;
//sensor_S1_FC_ABIERTO = RESET_boton;
//delay (50) ;
}
// **$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// programar alarmas
if( (( millis()- tiempoAnteriorTIMER_ON ) >= 5000) && ( sensor_S1_FC_ABIERTO == NO_PULSADA )
&& (FLAG_ERROR_S1_FC_ABIERTO == false) )
{
// programacion error se dirige a estado de reposo seguro
Serial.print(F(" Time Detencion ERROR sensor_S1_FC_ABIERTO : ===================> " ) );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ;
FLAG_ERROR_S1_FC_ABIERTO = true ; // existe error gestionar errores en una funcion de errores
}
if( (( millis()-tiempoAnteriorTIMER_ON) >= 5000) || sensor_S1_FC_ABIERTO == PULSADA )
{
// ejecutar apagado M1 secuencia // ARDUINO LOGICA +
digitalWrite( motor_M1_ABRIR_VALVULAS, LOW ); // apago M1 log- ESP 32 , se prende en INICIO SUBMENU 5.1
// falta consultar estado S de Micros SWITCH
digitalWrite(motor_M2_CEPILLO , HIGH); // 0 // PRENDO ARDUINO LOGICA +
digitalWrite(motor_M3_BOMBA , HIGH); // 2 // PRENDO ARDUINO LOGICA +
digitalWrite(electro_VALVULA , HIGH); // 15 // PRENDO ARDUINO LOGICA +
}
if( (millis() - tiempoAnteriorTIMER_ON) >= (tiempo_SICLO_ON_FILTRO*1000) || (tempSTATUS_TMRON == false) )
{
// ejecutar secuencia de cierrre valvula //* ARDUINO **!!! LOG +
digitalWrite(motor_M2_CEPILLO , LOW); // 0 // APAGAR LOG - POR HIGH
digitalWrite(motor_M3_BOMBA , LOW); // 2 //
digitalWrite(electro_VALVULA , LOW); // 15 //
}
if( tempSTATUS_TMRON == true )
{
ejecutarDETENCION_FILTRO();
// EJECUTAR SECUENCIA DE CIERRE VALVULAS // DEBE IR EN CONJUNTO CON UN BIT PIN OUT PARA SENTIDO GIRO CON 3 LELAYS
// digitalWrite( motor_M1_ABRIR_VALVULAS, HIGH ) ; // apago M1 log- ESP 32 , se prende en INICIO SUBMENU 5.1
}
}
// ejecutarDETENCION_FILTRO();
void ejecutarDETENCION_CIERRE_VALVULAS_FILTRO() // estado desactivado
{
if( (( millis()- tiempoAnteriorTIMER_ON ) >= (tiempo_SICLO_ON_FILTRO*1000) ) && (tempSTATUS_TMRON == true) )
{
//si ha transcurrido el tiempoMARCHA_FILTRO programado EJECUTAR FIN
//digitalWrite( motor_M1_ABRIR_VALVULAS , HIGH ) ; // apago filtro
FLAG_MARCHA_OK = false ; // una marcha por vez .. fin de marcha
tempSTATUS_TMRON = false ; //y desactivo el temporizador
Serial.print(F(" Time Detencion FILTRO: ===================> " ));
Serial.println( millis() );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ; //
}
// #define S1_FC_ABIERTO 3 //
// #define S2_FC_CERRADO 2 //
// **$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ en revicion 6 mayo $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
sensor_S1_FC_ABIERTO = !digitalRead(S1_FC_ABIERTO) ; // se guarda estado de S1
if( sensor_S1_FC_ABIERTO == PULSADA ) { // en logica ++
Serial.print(F(" Time Detencion ACTIVADO sensor_S1_FC_ABIERTO : ===================> " ) );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ; //
// FLAG_CONTROL_S1_FC_ABIERTO = true ; // OK pulsado una vez en el siclo de TIMER
control_botonS() ;
//sensor_S1_FC_ABIERTO = RESET_boton;
//delay (50) ;
}
// **$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// programar alarmas
if( (( millis()- tiempoAnteriorTIMER_ON ) >= 5000) && ( sensor_S1_FC_ABIERTO == NO_PULSADA )
&& (FLAG_ERROR_S1_FC_ABIERTO == false) )
{
// programacion error se dirige a estado de reposo seguro
Serial.print(F(" Time Detencion ERROR sensor_S1_FC_ABIERTO : ===================> " ) );
Serial.println( ( millis()- tiempoAnteriorTIMER_ON ) ) ;
FLAG_ERROR_S1_FC_ABIERTO = true ; // existe error gestionar errores en una funcion de errores
}
if( (( millis()-tiempoAnteriorTIMER_ON) >= 5000) || sensor_S1_FC_ABIERTO == PULSADA )
{
// ejecutar apagado M1 secuencia // ARDUINO LOGICA +
digitalWrite( motor_M1_ABRIR_VALVULAS, LOW ); // apago M1 log- ESP 32 , se prende en INICIO SUBMENU 5.1
// falta consultar estado S de Micros SWITCH
digitalWrite(motor_M2_CEPILLO , HIGH); // 0 // PRENDO ARDUINO LOGICA +
digitalWrite(motor_M3_BOMBA , HIGH); // 2 // PRENDO ARDUINO LOGICA +
digitalWrite(electro_VALVULA , HIGH); // 15 // PRENDO ARDUINO LOGICA +
}
if( (millis() - tiempoAnteriorTIMER_ON) >= (tiempo_SICLO_ON_FILTRO*1000) || (tempSTATUS_TMRON == false) )
{
// ejecutar secuencia de cierrre valvula //* ARDUINO **!!! LOG +
digitalWrite(motor_M2_CEPILLO , LOW); // 0 // APAGAR LOG - POR HIGH
digitalWrite(motor_M3_BOMBA , LOW); // 2 //
digitalWrite(electro_VALVULA , LOW); // 15 //
}
if( tempSTATUS_TMRON == true )
{
ejecutarDETENCION_FILTRO();
// EJECUTAR SECUENCIA DE CIERRE VALVULAS // DEBE IR EN CONJUNTO CON UN BIT PIN OUT PARA SENTIDO GIRO CON 3 LELAYS
// digitalWrite( motor_M1_ABRIR_VALVULAS, HIGH ) ; // apago M1 log- ESP 32 , se prende en INICIO SUBMENU 5.1
}
} // fin subrutina ejecutarDETENCION_CIERRE_VALVULAS_FILTRO()
void control_botonS()
{
if( boton_DERECHA == PULSADA )
{
Serial.print(F("BT R DERECHA menu_num "));
Serial.print( menu_num );
Serial.print(F(" sub_menu " ));
Serial.print( sub_menu );
Serial.print(F(" submenu1 " )) ;
Serial.println( submenu1 ); // PULSADO BT R
Serial.print(F(" modo LOC/REM " )) ;
Serial.print( MODO_FILTRO_LR ) ;
Serial.print(F(" modo AUT/MAN " )) ;
Serial.print( MODO_FILTRO ) ;
Serial.print(F(" Time ON FILTRO: " )) ;
Serial.print( tiempo_SICLO_ON_FILTRO ) ; // PULSADO BT R
Serial.print(F(" Time OFF FILTRO: " )) ;
Serial.println( tiempo_SICLO_OFF_FILTRO ) ; // PULSADO BT R
}
if( boton_IZQUIERDA == PULSADA )
{
Serial.print(F(" BT L IZQ menu_num "));
Serial.print( menu_num );
Serial.print(F(" sub_menu " ));
Serial.print( sub_menu );
Serial.print(F(" submenu1 " )) ;
Serial.println( submenu1 ); // PULSADO BT R
Serial.print(F(" modo LOC/REM " )) ;
Serial.print( MODO_FILTRO_LR ) ;
Serial.print(F(" modo AUT/MAN " )) ;
Serial.print( MODO_FILTRO ) ;
Serial.print(F(" modo AUT/MAN " )) ;
Serial.print( tiempo_SICLO_ON_FILTRO ) ; // PULSADO BT R
Serial.print(F(" Time OFF FILTRO: " )) ;
Serial.println( tiempo_SICLO_OFF_FILTRO ) ; // PULSADO BT R
}
if( boton_ENTER == PULSADA )
{
Serial.print(F(" BT ENTER menu_num ")); Serial.print( menu_num );
Serial.print(F(" sub_menu " )) ; Serial.print( sub_menu );
Serial.print(F(" submenu1 " )) ; Serial.println( submenu1 ); // PULSADO BT ENTER
Serial.print(F(" modo LOC/REM " )) ;
Serial.print( MODO_FILTRO_LR ) ;
Serial.print(F(" modo AUT/MAN " )) ;
Serial.print( MODO_FILTRO ) ;
Serial.print(F(" Time ON FILTRO: " )) ;
Serial.print( tiempo_SICLO_ON_FILTRO ) ; // PULSADO BT R
Serial.print(F(" Time OFF FILTRO: " )) ;
Serial.println( tiempo_SICLO_OFF_FILTRO ) ; // PULSADO BT R
}
if(boton_BACK == PULSADA )
{
Serial.print(F(" BT B BACK menu_num "));
Serial.print( menu_num );
Serial.print(F(" sub_menu " ));
Serial.print( sub_menu );
Serial.print(F(" submenu1 " )) ;
Serial.println( submenu1 ); // PULSADO BT BACK
Serial.print(F(" modo AUT/MAN " )) ;
Serial.print( MODO_FILTRO ) ;
Serial.print(F(" modo LOC/REM " )) ;
Serial.print( MODO_FILTRO_LR ) ;
Serial.print(F(" Time ON FILTRO: " )) ;
Serial.print( tiempo_SICLO_ON_FILTRO ) ; // PULSADO BT R
Serial.print(F(" Time OFF FILTRO: " )) ;
Serial.println( tiempo_SICLO_OFF_FILTRO ) ; // PULSADO BT R
}
} // fin void control_botonS