#include <Keypad.h>
#include <LiquidCrystal.h>
#define OUT 2
#define OUTTONE 3
#define SWITCHIN 13
#define TIMETONE 3000 //Tempo que o tom de tecla será emitido
#define TONEON 1000 //Frequencia do tom ao ligar
//Tamanho do teclado
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {4, 5, 6, 7};
byte colPins[COLS] = {8, 9, 10, 11};
Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);//LCD
String minutos = "";
String segundos = "";
int contador = 0;
String timeline = "";
//Monitor e LCD
void setup()
{
minutos = "";
segundos = "";
contador = 0;
Serial.begin(9600);
pinMode(OUT, OUTPUT);
pinMode(OUTTONE, OUTPUT);
pinMode(SWITCHIN, INPUT);
//Monitor Serial
lcd.begin(16,2);
lcd.clear();
//LCD
lcd.setCursor(3,0);
lcd.print("Microondas");
delay (1000);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Digite o tempo:");
lcd.setCursor(0,1);
lcd.print("(*)On (#)Apagar" );
}
//Teste da entrada
void loop()
{
char tecla = kpd.getKey(); //Confere se alguma tecla foi pressionada
if (tecla){
switch(tecla)
{
case 'A':
case 'B':
case 'C':
case 'D':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
//Armazenamento do tempo digitado
if(contador >= 3) {
break;
}
if(contador == 2) {
minutos = segundos.charAt(0);
segundos = segundos.charAt(1);
segundos += tecla;
} else {
segundos += tecla;
}
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Digite o Tempo:");
lcd.setCursor(1,1);
timeline = String(minutos) + String(":") + String(segundos);
lcd.print(timeline);
contador++;
break;
//Se a tecla # for pressionada a tela é limpa
case '#':
minutos = "";
segundos = "";
contador = 0;
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Digite o Tempo:");
break;
//Se a tecla * for pressionada, confirma a entrada do tempo
case'*':
long segundosInt = segundos.toInt();
long minutosInt = minutos.toInt();
lcd.clear();
//timer para marcar a passagem do tempo
while(segundosInt != 0 || minutosInt != 0) {
while(digitalRead(SWITCHIN) == HIGH) {
digitalWrite(OUT, LOW);
lcd.setCursor(1,1);
lcd.print("Feche a porta!");
}
digitalWrite(OUT, HIGH);
lcd.clear();
lcd.setCursor(1,0);
lcd.print(minutosInt);
lcd.print(":");
lcd.setCursor(2,0);
lcd.setCursor(3,0);
if(segundosInt < 10) {
lcd.print("0");
}
lcd.print(segundosInt);
if(segundosInt == 0 && minutosInt != 0) {
segundosInt = 60;
minutosInt--;
}
delay(1000);
segundosInt--;
}
digitalWrite(OUT, LOW);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Finalizado!!!");
tone(OUTTONE, TONEON, TIMETONE);
delay(2000);
setup();
}
}
}
Comments