/*
int estadoLed; //guarda el estado del led (encendido o apagado)
int periodo = 100; // tiempo que esta el LED en alto y bajo
unsigned long tiempoAnterior = 0; //guarda tiempo de referencia para comparar
void setup() {
pinMode(13,OUTPUT); //configura la salida
}
void loop() {
if(millis()-tiempoAnterior>=periodo){ //si ha transcurrido el periodo programado
estadoLed=!estadoLed; //cambia el estado del led cada 100ms
digitalWrite(13,estadoLed); //actualiza el estado del led
tiempoAnterior=millis(); //guarda el tiempo actual como referencia
}
}
*/
// =============================================================================================================
// --- 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 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);
// =============================================================================================================
// --- Protótipo das Funções ---
// void keyboard(); no se usa
void navegacionMenu();
void control_botonS() ; // para registro por puerto Serie
// =============================================================================================================
// --- Variáveis Globais ---
#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ções Iniciais ---
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(motor_M1_ABRIR_VALVULAS , OUTPUT); // 4 //
pinMode(motor_M2_CEPILLO , OUTPUT); // 0 //
pinMode(motor_M3_BOMBA , OUTPUT); // 2 //
pinMode(electro_VALVULA , OUTPUT); // 15 //
pinMode(S1_FC_ABIERTO , OUTPUT); // 25 //
pinMode(S2_FC_CERRADO , OUTPUT); // 26 //
lcd.begin(16, 2);
Serial.begin(9600);
} //end setup
// =============================================================================================================
// --- Configurações Iniciais ---
void loop()
{
// keyboard();
navegacionMenu() ;
} //end 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
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
// =======================================================================
// --- 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 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