Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "TimerOne.h"
- #include <LiquidCrystal_I2C.h>
- byte hora = 0;
- int hora1 = 0;
- byte minu = 0;
- int minu1 = 0;
- byte segu = 0;
- int segu1 = 0;
- unsigned long tempo = 0;
- unsigned long valor = 0;
- //#include <LiquidCrystal.h>
- //LiquidCrystal lcd(6, 7, 4, 5, 2, 3); //Configura os pinos do Arduino para se comunicar com o LCD
- LiquidCrystal_I2C lcd(0x38, 2, 1, 0, 7, 6, 5, 4, 3, POSITIVE); // Set the LCD I2C address
- //---------------------------------
- void setup()
- {
- lcd.begin(16,2);
- Serial.begin(9600);
- pinMode(13, OUTPUT);
- Timer1.initialize(1000000); // initialize timer1, and set a 1/2 second period
- Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
- }
- //--------------------------------------
- void callback()
- {
- digitalWrite(13, digitalRead(13) ^ 1);
- tempo++;
- if (tempo >= 86400) tempo = 0;
- }
- //--------------------------------------
- void loop()
- {
- if (Serial.available() > 0)
- {
- valor = Serial.parseInt();
- tempo = tempo + valor;
- }
- hora = tempo / 3600;
- hora1 = hora * 3600;
- minu1 = tempo - hora1;
- minu = minu1/60;
- segu1 = minu*60 + hora1;
- segu = tempo - segu1;
- lcd.setCursor(1,0);
- if (hora < 10)
- lcd.print("0");
- lcd.print(hora);
- lcd.print(":");
- if (minu < 10)
- lcd.print("0");
- lcd.print(minu);
- lcd.print(":");
- if (segu < 10)
- lcd.print("0");
- lcd.print(segu);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement