Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <relogio.h>
- #include <avr/pgmspace.h>
- #include <LiquidCrystal.h>
- const int pino_vcc =39;
- const int pino_gnd =37;
- const int pino_serial_clock=35;
- const int pino_data =33;
- const int pino_rst =31;
- int pinosRele[4] = {26,28,30,32};
- // Ordem de regar
- typedef struct OrdemRega{
- bool diasDeRega[7];
- int hora;
- int minuto;
- int segundo;
- int bombeadas;
- int rele;
- };
- OrdemRega regaPlanta;
- void resetaRega(){
- regaPlanta.hora=19;
- regaPlanta.minuto=30;
- regaPlanta.segundo=00;
- regaPlanta.diasDeRega[0]=true;
- regaPlanta.diasDeRega[1]=true;
- regaPlanta.diasDeRega[2]=true;
- regaPlanta.diasDeRega[3]=true;
- regaPlanta.diasDeRega[4]=true;
- regaPlanta.diasDeRega[5]=true;
- regaPlanta.diasDeRega[6]=true;
- regaPlanta.bombeadas=0;
- regaPlanta.rele=1;
- };
- char lcdMensagem[80];
- int lcdTempo=0;
- void showMessage(char* mensagem){
- strncpy(lcdMensagem,mensagem,70);
- lcdTempo=1000;
- };
- LiquidCrystal lcd(8,9,4,5,6,7);
- const int MODO_NORMAL=0;
- const int MODO_VERIFICA=1;
- const int MODO_CONFIGURA=2;
- const int MODO_AUTOTESTE=3;
- int modoAtual;
- void setup(){
- resetaRega();
- Serial.begin(9600);
- pinMode(pino_vcc, OUTPUT);
- pinMode(pino_gnd, OUTPUT);
- digitalWrite(pino_vcc,HIGH);
- digitalWrite(pino_gnd,LOW);
- Relogio::setup(pino_serial_clock, pino_data, pino_rst);
- //Relogio::setDateAndTime(16,04,15,23,50,00);
- modoAtual = MODO_NORMAL;
- lcd.begin(16,2);
- lcd.setCursor(0,0);
- lcd.print("Inicializado.");
- lcd.clear();
- };
- const int K_SELECT =1;
- const int K_LEFT =2;
- const int K_RIGHT =3;
- const int K_UP =4;
- const int K_DOWN =5;
- int leTeclado(){
- int comando = analogRead(0);
- if ((comando >= 0 )&&(comando <= 10))
- return K_RIGHT;
- if ((comando >= 250)&&(comando <= 260))
- return K_DOWN;
- if ((comando >= 400)&&(comando <= 420))
- return K_LEFT;
- if ((comando >= 90)&&(comando <= 110))
- return K_UP;
- if ((comando >= 630)&&(comando <= 650))
- return K_SELECT;
- return 0;
- };
- PROGMEM const char str0[]= "1)Nada" ;
- PROGMEM const char str1[]= "2)Verificar" ;
- PROGMEM const char str2[]= "3)Configurar" ;
- PROGMEM const char str3[]= "4)Auto-teste";
- PROGMEM const char* const COMANDOS_MENU[] ={str0,str1,str2,str3};
- PROGMEM const char str4[] = "1)Horario/Voltar";
- PROGMEM const char str5[] = "2)Dias da Semana";
- PROGMEM const char str6[] = "3)Acionamentos e Rele";
- PROGMEM const char str7[] = "4)Nao tem 4";
- PROGMEM const char* const PAGINAS_VERIFICA[] = {str4,str5,str6,str7};
- void autoTeste(){
- int i;
- for(i=0;i<3;i++){
- pinMode(pinosRele[i],OUTPUT);
- digitalWrite(pinosRele[i],HIGH);
- delay(1000);
- digitalWrite(pinosRele[i],LOW);
- };
- };
- void loop(){
- static int comandoAntigo=0;
- static int comandoAgora =0;
- static int comandoMenu=0;
- static int verificaPagina=0;
- Relogio::pisca();
- int hora;
- int minuto;
- int segundo;
- Relogio::getTime(&hora,&minuto,&segundo);
- char buf[30];
- // Controle pelo tecladinho
- comandoAntigo = comandoAgora;
- comandoAgora = leTeclado();
- switch(modoAtual){
- /*-------------------------------------
- Modo Normal
- -------------------------------------*/
- case MODO_NORMAL:
- // Mensagem no display
- if(lcdTempo>0){
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(lcdMensagem);
- delay(1000);
- lcdTempo=0;
- }else{
- lcd.setCursor(0,0);
- sprintf(buf,"%02d:%02d:%02d",hora,minuto,segundo);
- lcd.print(buf);
- // Controle
- if((comandoAgora!=comandoAntigo)&&(comandoAgora!=0)){
- lcd.clear();
- if((comandoMenu<0) || (comandoMenu>3)){
- comandoMenu=0;
- };
- switch(comandoAgora){
- case K_LEFT: if(comandoMenu>0) comandoMenu-- ; break; // Volta opção
- case K_RIGHT: if(comandoMenu<3) comandoMenu++ ; break; // Avança opção
- case K_SELECT: // Aciona opção
- switch(comandoMenu){
- case 0: comandoMenu=-1; break; // NADA
- case 1: modoAtual = MODO_VERIFICA; break;
- case 2: modoAtual = MODO_CONFIGURA; break;
- case 3: modoAtual = MODO_AUTOTESTE; break;
- };
- break;
- };
- };
- if(comandoMenu!=-1){
- strcpy_P(buf, (char*)pgm_read_word(&(COMANDOS_MENU[comandoMenu])));
- lcd.setCursor(0,1);
- lcd.print(buf);
- };
- return;
- };
- break;
- case MODO_VERIFICA:
- // Controle
- if((comandoAgora!=comandoAntigo)&&(comandoAgora!=0)){
- lcd.clear();
- switch(comandoAgora){
- case K_LEFT : if(verificaPagina>0) verificaPagina-- ;break;
- case K_RIGHT: if(verificaPagina<2) verificaPagina++ ;break;
- case K_SELECT:
- if(verificaPagina==0){
- modoAtual=MODO_NORMAL;
- return;
- };
- break;
- };
- };
- lcd.setCursor(0,0);
- switch(verificaPagina){
- case 0:
- sprintf(buf,"%02d:%02d:%02d",regaPlanta.hora,regaPlanta.minuto,regaPlanta.segundo); break;
- case 1:
- sprintf(buf,"S%dT%dQ%dQ%dS%dS%dD%d",
- regaPlanta.diasDeRega[0],
- regaPlanta.diasDeRega[1],
- regaPlanta.diasDeRega[2],
- regaPlanta.diasDeRega[3],
- regaPlanta.diasDeRega[4],
- regaPlanta.diasDeRega[5],
- regaPlanta.diasDeRega[6]);break;
- case 2:
- sprintf(buf,"%d x Rele %d",regaPlanta.bombeadas,regaPlanta.rele);
- break;
- };
- lcd.print(buf);
- strcpy_P(buf,(char*)pgm_read_word(&(PAGINAS_VERIFICA[verificaPagina])));
- lcd.setCursor(0,1);
- lcd.print(buf);
- break;
- case MODO_CONFIGURA:
- // Controle
- if((comandoAgora!=comandoAntigo)&&(comandoAgora!=0)){
- };
- break;
- case MODO_AUTOTESTE:
- autoTeste();
- modoAtual=MODO_NORMAL;
- break;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement