/*
Cronômetro com Arduino e display LCD I2C
Autor: Daniele Alberti
Modificações: tecdicas
18/10/2019
V1.0
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BTN_PLAY 10
#define BTN_STOP 11
int estado_btnplay;
int estado_btnstop;
unsigned long tempo;
unsigned long tempo_play = 0;
unsigned long tempo_stop;
unsigned long tempo_segundo;
int controle = 1;
// Alterar o endereço conforme modulo I2C
//LiquidCrystal_I2C lcd(0x3F, 2,1,0,4,5,6,7,3, POSITIVE);
LiquidCrystal_I2C lcd(0x27,20,4); //Atualiação de biblioteca
void setup()
{
pinMode(BTN_PLAY, INPUT_PULLUP);
pinMode(BTN_STOP, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Tec Dicas");
lcd.setCursor(0, 1);
lcd.print("Cronometro");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PLAY p/ iniciar");
}
void loop()
{
estado_btnplay = digitalRead (BTN_PLAY);
estado_btnstop = digitalRead (BTN_STOP);
if ((estado_btnplay == LOW) && (controle < 2))
{
tempo = millis();
controle = 0;
}
if ((estado_btnplay == LOW) && (controle == 2))
{
controle = 0;
}
if (controle == 0)
{
lcd.setCursor(0, 0);
lcd.print("TEMPO (segundo)");
lcd.setCursor(0, 1);
lcd.print("PLAY! ");
tempo_play = millis() - tempo;
tempo_segundo = tempo_play / 1000;
if (tempo_segundo <= 9)
{
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.print(tempo_segundo);
}
if ((tempo_segundo > 9) && (tempo_segundo <= 99))
{
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.print(tempo_segundo);
}
if ((tempo_segundo > 99) && (tempo_segundo <= 999))
{
lcd.setCursor(12, 1);
lcd.print(" ");
lcd.print(tempo_segundo);
}
if ((tempo_segundo > 999) && (tempo_segundo <= 9999))
{
lcd.setCursor(12, 1);
lcd.print(tempo_segundo);
}
}
if (estado_btnstop == LOW)
{
lcd.setCursor(0, 0);
lcd.print("TEMPO (milliseg)");
lcd.setCursor(0, 1);
lcd.print("STOP! ");
if ((tempo_play > 9) && (tempo_play <= 99))
{
lcd.setCursor(9, 1);
lcd.print(" ");
lcd.print(tempo_play);
}
if ((tempo_play > 99) && (tempo_play <= 999))
{
lcd.setCursor(9, 1);
lcd.print(" ");
lcd.print(tempo_play);
}
if ((tempo_play > 999) && (tempo_play <= 9999))
{
lcd.setCursor(9, 1);
lcd.print(" ");
lcd.print(tempo_play);
}
if ((tempo_play > 9999) && (tempo_play <= 99999))
{
lcd.setCursor(9, 1);
lcd.print(" ");
lcd.print(tempo_play);
}
if ((tempo_play > 99999) && (tempo_play <= 999999))
{
lcd.setCursor(9, 1);
lcd.print(" ");
lcd.print(tempo_play);
}
if ((tempo_play > 999999) && (tempo_play <= 9999999))
{
lcd.setCursor(9, 1);
lcd.print(tempo_play);
}
controle = 2;
}
}