//Programador:Rafael s.Melo
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int segundos = 20;
int entrada = 0;
int flag = 0;
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Aliment. Auto");
lcd.setCursor(0,1);
lcd.print("HELP PETZ");
delay(2000);
pinMode(2, INPUT_PULLUP);
pinMode(4, OUTPUT);
}
void loop()
{
entrada = digitalRead(2);
if (entrada == LOW ) {
flag = 1;
}
while(flag==1){
digitalWrite(4,HIGH);
segundos--;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tempo: ");
lcd.setCursor(8,1);
lcd.print("00:");
if(segundos<10){
lcd.print("0");
}
lcd.print(segundos);
delay(1000);
//Quando zerar o tempo
if(segundos == 0){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tempo Finalizado");
segundos = 20;
flag = 0;
digitalWrite(3, LOW);
delay(3000);
}
}
//Quando parado, mostra no lcd
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Tempo:");
lcd.setCursor(8,1);
lcd.print("00:");
lcd.print(segundos);
delay(200);
}