Advertisement
Guest User

Funkuhr an 7- Segment

a guest
Nov 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DCF77.h"
  2. #include "TimeLib.h"
  3.  
  4. char time_s[9];
  5. char date_s[11];
  6.  
  7. #define DCF_PIN 2           // Connection pin to DCF 77 device
  8. #define DCF_INTERRUPT 0    // Interrupt number associated with pin
  9.  
  10. time_t time;
  11. DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT);
  12.  
  13. void setup() {
  14.   Serial.begin(9600);
  15.   DCF.Start();
  16.   Serial.println("Warte auf Zeitsignal ... ");
  17.   Serial.println("Dies kann 2 oder mehr Minuten dauern.");
  18. }
  19.  
  20. void loop() {
  21.  
  22.   delay(1000);
  23.   time_t DCFtime = DCF.getTime(); // Nachschauen ob eine neue DCF77 Zeit vorhanden ist
  24.   if (DCFtime!=0)
  25.   {
  26.     setTime(DCFtime); //Neue Systemzeit setzen
  27.     Serial.print("Neue Zeit erhalten : "); //Ausgabe an seriell
  28.     Serial.print(sprintTime());
  29.     Serial.print("  ");
  30.     Serial.println(sprintDate());  
  31.   }
  32.   //---> hier könnte man die Ausgabe auch auf ein LCD schicken.
  33. }
  34.  
  35. char* sprintTime() {
  36.   snprintf(time_s,sizeof(time_s),"%.2d:%.2d:%.2d" , hour(), minute(), second());
  37.   time_s[strlen(time_s)] = '\0';
  38.   return time_s;
  39. }
  40.  
  41. char* sprintDate() {
  42.   snprintf(date_s,sizeof(date_s),"%.2d.%.2d.%.4d" , day(), month(), year());
  43.   date_s[strlen(date_s)] = '\0';
  44.   return date_s;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement