Advertisement
RuiViana

RelogioTimer1

Jun 22nd, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1.   #include "TimerOne.h"
  2.   #include <LiquidCrystal_I2C.h>
  3.   byte hora = 0;
  4.   int hora1 = 0;
  5.   byte minu = 0;
  6.   int minu1 = 0;
  7.   byte segu = 0;
  8.   int segu1 = 0;
  9.   unsigned long tempo = 0;
  10.   unsigned long valor = 0;
  11. //#include <LiquidCrystal.h>
  12.  
  13. //LiquidCrystal lcd(6, 7, 4, 5, 2, 3); //Configura os pinos do Arduino para se comunicar com o LCD
  14.  LiquidCrystal_I2C lcd(0x38,  2, 1, 0, 7, 6, 5, 4, 3, POSITIVE);  // Set the LCD I2C address
  15.   //---------------------------------
  16.   void setup()
  17.   {
  18.     lcd.begin(16,2);
  19.     Serial.begin(9600);
  20.     pinMode(13, OUTPUT);
  21.     Timer1.initialize(1000000);         // initialize timer1, and set a 1/2 second period
  22.     Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
  23.   }
  24.   //--------------------------------------
  25.   void callback()
  26.   {
  27.     digitalWrite(13, digitalRead(13) ^ 1);
  28.     tempo++;
  29.     if (tempo >= 86400) tempo = 0;
  30.   }
  31.   //--------------------------------------
  32.   void loop()
  33.   {
  34.     if (Serial.available() > 0)
  35.     {
  36.       valor =  Serial.parseInt();
  37.       tempo = tempo + valor;
  38.     }
  39.     hora = tempo / 3600;
  40.     hora1 = hora * 3600;
  41.     minu1 = tempo - hora1;
  42.     minu = minu1/60;
  43.     segu1 = minu*60 + hora1;
  44.     segu = tempo - segu1;
  45.    
  46.     lcd.setCursor(1,0);
  47.     if (hora < 10)
  48.       lcd.print("0");
  49.     lcd.print(hora);
  50.     lcd.print(":");
  51.     if (minu < 10)
  52.       lcd.print("0");
  53.     lcd.print(minu);
  54.     lcd.print(":");    
  55.     if (segu < 10)
  56.       lcd.print("0");      
  57.     lcd.print(segu);    
  58.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement