Advertisement
RuiViana

Untitled

Jun 6th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. int seg=0, // Variavél para segundos
  2. min=0, // Variavél para minuto
  3. hor=0; // Variavél para horas
  4.  
  5. void setup()
  6. {
  7. Serial.begin(9600); // Inkicializa serial
  8. }
  9.  
  10. void loop()
  11. {
  12. static unsigned long ult_tempo = 0; // Zera o valor da variavel "ult_tempo"
  13. int tempo = millis(); // Carrega o valor lido por miilis() na variavél tempo
  14. if(tempo - ult_tempo >= 1000) // Faça os proximos comandos se a diferença da var tempo e ult_tempo for maior que 1000
  15. {
  16. ult_tempo = tempo; // Se for, faça ult_tempo = tempo (salve o valor da ultima leitura de miilis)
  17. seg++; // Incremente segundos
  18. }
  19. if(seg>=60) // Se segundos for maior que 60
  20. {
  21. seg = 0; // Zere segundos
  22. min++; // E incremente minutos
  23. }
  24. if(min>=60) // Se minutos for maior que 60
  25. {
  26. min = 0; // Zere minutos
  27. hor++; // E incremente horas
  28. }
  29. Serial.print(hor); // Imprima horas
  30. Serial.print(":"); // Imprima :
  31. Serial.print(min); // Imprima minutos
  32. Serial.print(":"); // Imprima :
  33. Serial.println(seg); // Imprima segundos
  34. delay(1000); // Delay de 1 minuto
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement