//******************************************************************************************************
// Aquario - Fish Tank
// Autor: Joao Pereira
// Email: joaodper@gmail.com
// Data: 11/07/2017
//
// ****************** EEPROM Memory Map *********************************** BUTTONS ****************
// Byte 0 -> Luzes ON hora Byte 09 -> Filtro OFF 1 hora * 128 -> botao down
// Byte 1 -> Luzes ON minuto Byte 10 -> Filtro OFF 1 minuto * 32 -> botao up
// Byte 2 -> Luzes ON segundo Byte 11 -> Filtro OFF 1 segundo * 16 -> botao left
// Byte 3 -> Luzes OFF hora Byte 13 -> Filtro ON 2 hora * 64 -> botao right
// Byte 4 -> Luzes OFF minuto Byte 14 -> Filtro ON 2 minuto * 2 -> botao exit
// Byte 5 -> Luzes OFF segundo Byte 15 -> Filtro OFF 2 hora * 1 -> botao enter
// Byte 6 -> Filtro ON 1 hora Byte 16 -> Filtro OFF 2 minuto * 8 -> botao toggle filtro
// Byte 7 -> Filtro ON 1 minuto * 4 -> botao toggle luzes
// Byte 8 -> Filtro ON 1 segundo Byte 12 -> Termometro *
//*******************************************************************************************************
// Serial
//
//
//
//*******************************************************************************************************
#include <LiquidCrystal.h> // LCD library
#include <OneWire.h> // DS18B20 library - http://labdegaragem.com/profiles/blogs/tutorial-como-utilizar-o-sensor-de-temperatura-ds18b20-prova-de
#include <DS1307.h> // RTC DS1307 library - http://blog.filipeflop.com/modulos/relogio-rtc-ds1307-arduino.html
#include <EEPROM.h> // Internal EEPROM library
#include <Wire.h>
//*************** Configuracoes das entradas e saidas ***************************************************
int interrupt_id = 2;
volatile int interupcao = 0;
byte button = 0;
const int ledPin = 13;
const int porta5 = 5;
int menuState = 1;
int count_time = 0;
int count = 29;
// Valores guardados na memoria
int hora_luz_on = EEPROM.read(0);
int minuto_luz_on = EEPROM.read(1);
int hora_luz_off = EEPROM.read(3);
int minuto_luz_off = EEPROM.read(4);
int hora_filtro_on = EEPROM.read(6);
int minuto_filtro_on = EEPROM.read(7);
int hora_filtro_off = EEPROM.read(9);
int minuto_filtro_off = EEPROM.read(10);
int hora_filtro_on2 = EEPROM.read(13);
int minuto_filtro_on2 = EEPROM.read(14);
int hora_filtro_off2 = EEPROM.read(15);
int minuto_filtro_off2 = EEPROM.read(16);
int temp1 = EEPROM.read(12);
int luzes_state = 1; //para acertar o horario das luzes
int filtro_state = 1; //para acertar o horario dos filtros
int horas_state = 1; //para acertar as horas e a data
volatile boolean luzes_print = false;
volatile boolean filtro_print = false;
volatile boolean apresenta_tela = true; // serve para apresentar cada tela 1 s vez
int lcd_coluna = 0;
int lcd_linha = 0;
boolean cursor_on = false;
// variveis para alternar o cursor
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 1000; // interval at which to blink (milliseconds)
//Inicializa o LCD
LiquidCrystal lcd(8, 7, 9, 10, 11, 12);
//Inicializa o DS18B20 na porta 2
OneWire ds(6); // no pino 6
//Inicializa o RTC DS1307 ligado as portas A4 e A5 do Arduino
DS1307 rtc(4, 3);
Time t;
int dia_set = t.date;
int mes_set = t.mon;
int ano_set = t.year;
int horas_set = t.hour;
int minutos_set = t.min;
int segundos_set = t.sec;
//**************************************** SETUP ********************************************
void setup(void) {
pinMode(interrupt_id, INPUT_PULLUP);
attachInterrupt(0, _interrupcao, FALLING); // Definio do Interrupt:(O Interrupt a usar, funo para ser executada, Executar quando for de LOW para HIGH
Wire.begin();
//Configura entradas e saidas
pinMode(ledPin, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(porta5, OUTPUT);
// Limpa o PCF8574
Wire.beginTransmission(32);
Wire.write(B11111111);
Wire.endTransmission();
//Liga o relogio
rtc.halt(false);
//As linhas abaixo setam a data e hora do modulo e podem ser comentada apos a primeira utilizacao
//rtc.setDOW(FRIDAY); //Define o dia da semana
//Definicoes do pino SQW/Out
rtc.setSQWRate(SQW_RATE_1);
rtc.enableSQW(true);
Serial.begin(9600);
//Setup do LCD com o nmnero de colunas x linhas
lcd.begin(20, 4);
// fazer verificacao em caso de falha a energia eletrica
// Luzes
// Filtro
}
//**************************** Interrupt Function ****************************************
void _interrupcao() {
interupcao = 1;
}
//*******************************************************************************************
void loop(void) {
button == 0;
float celsius = getTemp();
// Conta para apagar a luz do lcd
count_time = count_time + 1;
count = count + 1;
if (count_time == 120) {
digitalWrite(ledPin, LOW);
menuState = 1;
}
if (menuState == 1) {
cursor_on = false;
telas(menuState, celsius);
}
if(interupcao == 1){
interupcao = 0;
Wire.requestFrom(32,1); //Se PCF8574M - adrress = 32
if(Wire.available()) //If the request is available
{
button=Wire.read(); //Receive the data
//Serial.println(button);
}
menuState = botoes(menuState, button);
if(apresenta_tela == true){
telas(menuState, celsius);
apresenta_tela = false;
}
}
alarmes(celsius);
delay (100);
//criar funcao parar piscar os cursor
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if(cursor_on == true){
lcd.setCursor(lcd_coluna, lcd_linha);
lcd.cursor();
}
}
else {
lcd.noCursor();
}
}
//*******************************************************************************************
int botoes(int State, int button) {
//Serial.println(State);
if (button == 1 || button == 2 || button == 4 || button == 8 || button == 64 || button == 32 || button == 16 || button == 128) {
// turn LED on
count_time = 0;
digitalWrite(ledPin, HIGH);
}
// Botoes para a Tela 1
if (State == 1 && button == 1){
apresenta_tela = true;
cursor_on = false;
return 2;
}
// Botoes para a Tela 2 -> Configuracoes (Data e Hora)
if (State == 2 && button == 128){
apresenta_tela = true;
cursor_on = false;
return 3;
}
if (State == 2 && button == 32){
apresenta_tela = true;
cursor_on = false;
return 5;
}
if (State == 2 && button == 1){
apresenta_tela = true;
lcd_coluna = 7;
lcd_linha = 1;
cursor_on = true;
horas_set = t.hour;
minutos_set = t.min;
segundos_set = t.sec;
dia_set = t.date;
mes_set = t.mon;
ano_set = t.year;
return 9;
}
if (State == 2 && button == 2){
apresenta_tela = true;
cursor_on = false;
return 1;
}
if (State == 2 && button == 16){
apresenta_tela = true;
cursor_on = false;
return 10; //Apresenta a Tela 9 -> Sobre
}
// Botoes para a Tela 2 -> Configuracoes (Temperatura)
if (State == 3 && button == 128){
apresenta_tela = true;
cursor_on = false;
return 4;
}
if (State == 3 && button == 32){
apresenta_tela = true;
cursor_on = false;
return 2;
}
if (State == 3 && button == 1){
apresenta_tela = true;
lcd_coluna = 14;
lcd_linha = 1;
cursor_on = true;
return 6;
}
if (State == 3 && button == 2){
apresenta_tela = true;
return 1;
}
// Botoes para a Tela 2 -> Configuracoes (Luzes)
if (State == 4 && button == 128){
apresenta_tela = true;
return 5;
}
if (State == 4 && button == 32){
apresenta_tela = true;
return 3;
}
if (State == 4 && button == 1){
apresenta_tela = true;
lcd_coluna = 6;
lcd_linha = 1;
cursor_on = true;
return 7;
}
if (State == 4 && button == 2){
apresenta_tela = true;
return 1;
}
// Botoes para a Tela 2 -> Configuracoes (Filtro)
if (State == 5 && button == 128){
apresenta_tela = true;
return 2;
}
if (State == 5 && button == 32){
apresenta_tela = true;
return 4;
}
if (State == 5 && button == 1){
apresenta_tela = true;
lcd_coluna = 6;
lcd_linha = 1;
cursor_on = true;
return 8;
}
if (State == 5 && button == 2){
apresenta_tela = true;
return 1;
}
// Botoes para a Tela 3 -> Temperatura
if (State == 6 && button == 32){
temp1 = temp1 + 1;
lcd_coluna = 14;
lcd_linha = 1;
cursor_on = true;
lcd.setCursor(13, 1);
if(temp1 <= 9){
lcd.print("0");
}
lcd.print(temp1);
EEPROM.write(12,temp1);
}
if (State == 6 && button == 128){
temp1 = temp1 - 1;
lcd_coluna = 14;
lcd_linha = 1;
cursor_on = true;
lcd.setCursor(13, 1);
if(temp1 <= 9){
lcd.print("0");
}
lcd.print(temp1);
EEPROM.write(12,temp1);
}
if (State == 6 && button == 2){
apresenta_tela = true;
cursor_on = false;
return 3;
}
// Botoes para a Tela 4 -> Luzes
//button up
if (State == 7 && button == 32){
if (luzes_state == 1){
hora_luz_on = hora_luz_on + 1;
if (hora_luz_on == 24) { hora_luz_on = 0; }
cursor_on = true;
lcd.setCursor(5, 1);
if(hora_luz_on <= 9){
lcd.print("0");
}
lcd.print(hora_luz_on);
}
if (luzes_state == 2){
minuto_luz_on = minuto_luz_on + 1;
if (minuto_luz_on == 60) { minuto_luz_on = 0; }
cursor_on = true;
lcd.setCursor(8, 1);
if(minuto_luz_on <= 9){
lcd.print("0");
}
lcd.print(minuto_luz_on);
}
if (luzes_state == 3){
hora_luz_off = hora_luz_off + 1;
if (hora_luz_off == 24) { hora_luz_off = 0; }
cursor_on = true;
lcd.setCursor(5, 2);
if(hora_luz_off <= 9){
lcd.print("0");
}
lcd.print(hora_luz_off);
}
if (luzes_state == 4){
minuto_luz_off = minuto_luz_off + 1;
if (minuto_luz_off == 60) { minuto_luz_off = 0; }
cursor_on = true;
lcd.setCursor(8, 2);
if(minuto_luz_off <= 9){
lcd.print("0");
}
lcd.print(minuto_luz_off);
}
EEPROM.write(0,hora_luz_on);
EEPROM.write(1,minuto_luz_on);
EEPROM.write(3,hora_luz_off);
EEPROM.write(4,minuto_luz_off);
}
// down button
if (State == 7 && button == 128){
if (luzes_state == 1){
hora_luz_on = hora_luz_on - 1;
if (hora_luz_on == -1) { hora_luz_on = 23; }
cursor_on = true;
lcd.setCursor(5, 1);
if(hora_luz_on <= 9){
lcd.print("0");
}
lcd.print(hora_luz_on);
}
if (luzes_state == 2){
minuto_luz_on = minuto_luz_on - 1;
if (minuto_luz_on == -1) { minuto_luz_on = 59; }
cursor_on = true;
lcd.setCursor(8, 1);
if(minuto_luz_on <= 9){
lcd.print("0");
}
lcd.print(minuto_luz_on);
}
if (luzes_state == 3){
hora_luz_off = hora_luz_off - 1;
if (hora_luz_off == -1) {hora_luz_off = 23; }
cursor_on = true;
lcd.setCursor(5, 2);
if(hora_luz_off <= 9){
lcd.print("0");
}
lcd.print(hora_luz_off);
}
if (luzes_state == 4){
minuto_luz_off = minuto_luz_off - 1;
if (minuto_luz_off == -1) { minuto_luz_off = 59; }
cursor_on = true;
lcd.setCursor(8, 2);
if(minuto_luz_off <= 9){
lcd.print("0");
}
lcd.print(minuto_luz_off);
}
EEPROM.write(0,hora_luz_on);
EEPROM.write(1,minuto_luz_on);
EEPROM.write(3,hora_luz_off);
EEPROM.write(4,minuto_luz_off);
}
// left button
if (State == 7 && button == 16){
luzes_state = luzes_state + 1;
if (luzes_state == 5){luzes_state = 1;}
if (luzes_state == 1){
lcd_coluna = 6;
lcd_linha = 1;
}
if (luzes_state == 2){
lcd_coluna = 9;
lcd_linha = 1;
}
if (luzes_state == 3){
lcd_coluna = 6;
lcd_linha = 2;
}
if (luzes_state == 4){
lcd_coluna = 9;
lcd_linha = 2;
}
}
//right button
if (State == 7 && button == 64){
luzes_state = luzes_state - 1;
if (luzes_state == 0){luzes_state = 4;}
if (luzes_state == 1){
lcd_coluna = 6;
lcd_linha = 1;
}
if (luzes_state == 2){
lcd_coluna = 9;
lcd_linha = 1;
}
if (luzes_state == 3){
lcd_coluna = 6;
lcd_linha = 2;
}
if (luzes_state == 4){
lcd_coluna = 9;
lcd_linha = 2;
}
}
if (State == 7 && button == 2){
apresenta_tela = true;
cursor_on = false;
return 4;
}
// Botoes para a Tela 5 -> Filtro (State 8)
//button up
if (State == 8 && button == 32){
if (filtro_state == 1){
hora_filtro_on = hora_filtro_on + 1;
if (hora_filtro_on == 24) { hora_filtro_on = 0; }
cursor_on = true;
lcd.setCursor(5, 1);
if(hora_filtro_on <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_on);
}
if (filtro_state == 2){
minuto_filtro_on = minuto_filtro_on + 1;
if (minuto_filtro_on == 60) { minuto_filtro_on = 0; }
cursor_on = true;
lcd.setCursor(8, 1);
if(minuto_filtro_on <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_on);
}
if (filtro_state == 3){
hora_filtro_off = hora_filtro_off + 1;
if (hora_filtro_off == 24) { hora_filtro_off = 0; }
cursor_on = true;
lcd.setCursor(5, 2);
if(hora_filtro_off <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_off);
}
if (filtro_state == 4){
minuto_filtro_off = minuto_filtro_off + 1;
if (minuto_filtro_off == 60) { minuto_filtro_off = 0; }
cursor_on = true;
lcd.setCursor(8, 2);
if(minuto_filtro_off <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_off);
}
if (filtro_state == 5){
hora_filtro_on2 = hora_filtro_on2 + 1;
if (hora_filtro_on2 == 24) { hora_filtro_on2 = 0; }
cursor_on = true;
lcd.setCursor(12, 1);
if(hora_filtro_on2 <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_on2);
}
if (filtro_state == 6){
minuto_filtro_on2 = minuto_filtro_on2 + 1;
if (minuto_filtro_on2 == 60) { minuto_filtro_on2 = 0; }
cursor_on = true;
lcd.setCursor(15, 1);
if(minuto_filtro_on2 <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_on2);
}
if (filtro_state == 7){
hora_filtro_off2 = hora_filtro_off2 + 1;
if (hora_filtro_off2 == 24) { hora_filtro_off2 = 0; }
cursor_on = true;
lcd.setCursor(12, 2);
if(hora_filtro_off2 <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_off2);
}
if (filtro_state == 8){
minuto_filtro_off2 = minuto_filtro_off2 + 1;
if (minuto_filtro_off2 == 60) { minuto_filtro_off2 = 0; }
cursor_on = true;
lcd.setCursor(15, 2);
if(minuto_filtro_off2 <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_off2);
}
EEPROM.write(6,hora_filtro_on);
EEPROM.write(7,minuto_filtro_on);
EEPROM.write(9,hora_filtro_off);
EEPROM.write(10,minuto_filtro_off);
EEPROM.write(13,hora_filtro_on2);
EEPROM.write(14,minuto_filtro_on2);
EEPROM.write(15,hora_filtro_off2);
EEPROM.write(16,minuto_filtro_off2);
}
// down button
if (State == 8 && button == 128){
if (filtro_state == 1){
hora_filtro_on = hora_filtro_on - 1;
if (hora_filtro_on == -1) { hora_filtro_on = 23; }
cursor_on = true;
lcd.setCursor(5, 1);
if(hora_filtro_on <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_on);
}
if (filtro_state == 2){
minuto_filtro_on = minuto_filtro_on - 1;
if (minuto_filtro_on == -1) { minuto_filtro_on = 59; }
cursor_on = true;
lcd.setCursor(8, 1);
if(minuto_filtro_on <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_on);
}
if (filtro_state == 3){
hora_filtro_off = hora_filtro_off - 1;
if (hora_filtro_off == -1) {hora_filtro_off = 23; }
cursor_on = true;
lcd.setCursor(5, 2);
if(hora_filtro_off <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_off);
}
if (filtro_state == 4){
minuto_filtro_off = minuto_filtro_off - 1;
if (minuto_filtro_off == -1) { minuto_filtro_off = 59; }
cursor_on = true;
lcd.setCursor(8, 2);
if(minuto_filtro_off <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_off);
}
if (filtro_state == 5){
hora_filtro_on2 = hora_filtro_on2 - 1;
if (hora_filtro_on2 == -1) { hora_filtro_on2 = 23; }
cursor_on = true;
lcd.setCursor(12, 1);
if(hora_filtro_on2 <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_on2);
}
if (filtro_state == 6){
minuto_filtro_on2 = minuto_filtro_on2 - 1;
if (minuto_filtro_on2 == -1) { minuto_filtro_on2 = 59; }
cursor_on = true;
lcd.setCursor(15, 1);
if(minuto_filtro_on2 <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_on2);
}
if (filtro_state == 7){
hora_filtro_off2 = hora_filtro_off2 - 1;
if (hora_filtro_off2 == -1) {hora_filtro_off2 = 23; }
cursor_on = true;
lcd.setCursor(12, 2);
if(hora_filtro_off2 <= 9){
lcd.print("0");
}
lcd.print(hora_filtro_off2);
}
if (filtro_state == 8){
minuto_filtro_off2 = minuto_filtro_off2 - 1;
if (minuto_filtro_off2 == -1) { minuto_filtro_off2 = 59; }
cursor_on = true;
lcd.setCursor(15, 2);
if(minuto_filtro_off2 <= 9){
lcd.print("0");
}
lcd.print(minuto_filtro_off2);
}
EEPROM.write(6,hora_filtro_on);
EEPROM.write(7,minuto_filtro_on);
EEPROM.write(9,hora_filtro_off);
EEPROM.write(10,minuto_filtro_off);
EEPROM.write(13,hora_filtro_on2);
EEPROM.write(14,minuto_filtro_on2);
EEPROM.write(15,hora_filtro_off2);
EEPROM.write(16,minuto_filtro_off2);
}
// left button
if (State == 8 && button == 16){
filtro_state = filtro_state + 1;
if (filtro_state == 9){filtro_state = 1;}
if (filtro_state == 1){
lcd_coluna = 6;
lcd_linha = 1;
}
if (filtro_state == 2){
lcd_coluna = 9;
lcd_linha = 1;
}
if (filtro_state == 3){
lcd_coluna = 6;
lcd_linha = 2;
}
if (filtro_state == 4){
lcd_coluna = 9;
lcd_linha = 2;
}
if (filtro_state == 5){
lcd_coluna = 13;
lcd_linha = 1;
}
if (filtro_state == 6){
lcd_coluna = 16;
lcd_linha = 1;
}
if (filtro_state == 7){
lcd_coluna = 13;
lcd_linha = 2;
}
if (filtro_state == 8){
lcd_coluna = 16;
lcd_linha = 2;
}
}
//right button
if (State == 8 && button == 64){
filtro_state = filtro_state - 1;
if (filtro_state == 0){filtro_state = 8;}
if (filtro_state == 1){
lcd_coluna = 6;
lcd_linha = 1;
}
if (filtro_state == 2){
lcd_coluna = 9;
lcd_linha = 1;
}
if (filtro_state == 3){
lcd_coluna = 6;
lcd_linha = 2;
}
if (filtro_state == 4){
lcd_coluna = 9;
lcd_linha = 2;
}
if (filtro_state == 5){
lcd_coluna = 13;
lcd_linha = 1;
}
if (filtro_state == 6){
lcd_coluna = 16;
lcd_linha = 1;
}
if (filtro_state == 7){
lcd_coluna = 13;
lcd_linha = 2;
}
if (filtro_state == 8){
lcd_coluna = 16;
lcd_linha = 2;
}
}
if (State == 8 && button == 2){
apresenta_tela = true;
cursor_on = false;
return 5;
}
// Botoes para a Tela 9 -> Hora e Data
if (State == 9 && button == 2){
apresenta_tela = true;
cursor_on = false;
return 2;
}
if (State == 9 && button == 1){
apresenta_tela = true;
cursor_on = false;
return 2;
}
//button up
if (State == 9 && button == 32){
if (horas_state == 1){
dia_set = dia_set + 1;
if (dia_set == 32) { dia_set = 1; }
cursor_on = true;
lcd.setCursor(6, 1);
if(dia_set <= 9){
lcd.print("0");
}
lcd.print(dia_set);
}
if (horas_state == 2){
mes_set = mes_set + 1;
if (mes_set == 13) { mes_set = 1; }
cursor_on = true;
lcd.setCursor(9, 1);
if(mes_set <= 9){
lcd.print("0");
}
lcd.print(mes_set);
}
if (horas_state == 3){
ano_set = ano_set + 1;
if (ano_set == 2100) { ano_set = 2000; }
cursor_on = true;
lcd.setCursor(12, 1);
if(ano_set <= 9){
lcd.print("0");
}
lcd.print(ano_set);
}
if (horas_state == 4){
horas_set = horas_set + 1;
if (horas_set == 24) { horas_set = 0; }
cursor_on = true;
lcd.setCursor(6, 2);
if(horas_set <= 9){
lcd.print("0");
}
lcd.print(horas_set);
}
if (horas_state == 5){
minutos_set = minutos_set + 1;
if (minutos_set == 60) { minutos_set = 0; }
cursor_on = true;
lcd.setCursor(9, 2);
if(minutos_set <= 9){
lcd.print("0");
}
lcd.print(minutos_set);
}
if (horas_state == 6){
segundos_set = segundos_set + 1;
if (segundos_set == 60) { segundos_set = 0; }
cursor_on = true;
lcd.setCursor(12, 2);
if(segundos_set <= 9){
lcd.print("0");
}
lcd.print(segundos_set);
}
rtc.setTime(horas_set, minutos_set, segundos_set); //Define o hora, minuto, segundo
rtc.setDate(dia_set, mes_set, ano_set); //Define o dia, mes e ano
}
// button down
if (State == 9 && button == 128){
if (horas_state == 1){
dia_set = dia_set - 1;
if (dia_set == 0) { dia_set = 31; }
cursor_on = true;
lcd.setCursor(6, 1);
if(dia_set <= 9){
lcd.print("0");
}
lcd.print(dia_set);
}
if (horas_state == 2){
mes_set = mes_set - 1;
if (mes_set == 0) { mes_set = 12; }
cursor_on = true;
lcd.setCursor(9, 1);
if(mes_set <= 9){
lcd.print("0");
}
lcd.print(mes_set);
}
if (horas_state == 3){
ano_set = ano_set - 1;
if (ano_set == 2000) { ano_set = 2100; }
cursor_on = true;
lcd.setCursor(12, 1);
if(ano_set <= 9){
lcd.print("0");
}
lcd.print(ano_set);
}
if (horas_state == 4){
horas_set = horas_set - 1;
if (horas_set == 0) { horas_set = 24; }
cursor_on = true;
lcd.setCursor(6, 2);
if(horas_set <= 9){
lcd.print("0");
}
lcd.print(horas_set);
}
if (horas_state == 5){
minutos_set = minutos_set - 1;
if (minutos_set == 0) { minutos_set = 60; }
cursor_on = true;
lcd.setCursor(9, 2);
if(minutos_set <= 9){
lcd.print("0");
}
lcd.print(minutos_set);
}
if (horas_state == 6){
segundos_set = segundos_set - 1;
if (segundos_set == 0) { segundos_set = 60; }
cursor_on = true;
lcd.setCursor(12, 2);
if(segundos_set <= 9){
lcd.print("0");
}
lcd.print(segundos_set);
}
rtc.setTime(horas_set, minutos_set, segundos_set); //Define o hora, minuto, segundo
rtc.setDate(dia_set, mes_set, ano_set); //Define o dia, mes e ano
}
// right button
if (State == 9 && button == 16){
horas_state = horas_state + 1;
if (horas_state == 7){horas_state = 1;}
if (horas_state == 1){
lcd_coluna = 7;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 2){
lcd_coluna = 10;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 3){
lcd_coluna = 13;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 4){
lcd_coluna = 7;
lcd_linha = 2;
cursor_on = true;
}
if (horas_state == 5){
lcd_coluna = 10;
lcd_linha = 2;
cursor_on = true;
}
if (horas_state == 6){
lcd_coluna = 13;
lcd_linha = 2;
cursor_on = true;
}
}
// left button
if (State == 9 && button == 64){
horas_state = horas_state - 1;
if (horas_state == 0){horas_state = 6;}
if (horas_state == 1){
lcd_coluna = 7;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 2){
lcd_coluna = 10;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 3){
lcd_coluna = 13;
lcd_linha = 1;
cursor_on = true;
}
if (horas_state == 4){
lcd_coluna = 7;
lcd_linha = 2;
cursor_on = true;
}
if (horas_state == 5){
lcd_coluna = 10;
lcd_linha = 2;
cursor_on = true;
}
if (horas_state == 6){
lcd_coluna = 13;
lcd_linha = 2;
cursor_on = true;
}
}
// Botoes para a Tela 10 -> Sobre
if (State == 10 && button == 2){
return 1;
}
// Botao toggle luz
if (button == 4){
digitalWrite(A0, !digitalRead(A0));
luzes_print = !luzes_print;
}
// Botao toggle filtro
if (button == 8){
digitalWrite(A1, !digitalRead(A1));
digitalWrite(porta5, !digitalRead(porta5));
filtro_print = !filtro_print;
}
return State;
}
//*******************************************************************************************
void telas(int var, float celsius){
...
This file has been truncated, please download it to see its full contents.
Comments
Please log in or sign up to comment.