Modifications

Sauter à la navigation Sauter à la recherche
399 octets ajoutés ,  22 janvier 2013 à 07:54
Ligne 134 : Ligne 134 :  
== Lire l'heure ==
 
== Lire l'heure ==
   −
Now that the RTC is merrily ticking away, we'll want to query it for the time. Lets look at the sketch again to see how this is done
+
Maintenant que le RTC égraine le temps, nous allons l'utiliser pour récupérer l'heure. Retournons à notre sketch pour voir comment c'est fait
    
  <nowiki>void loop () {
 
  <nowiki>void loop () {
 
     DateTime now = RTC.now();
 
     DateTime now = RTC.now();
 
      
 
      
     Serial.print(now.year(), DEC);
+
     Serial.print(now.year(), DEC);   // Affichage ANNEE
 
     Serial.print('/');
 
     Serial.print('/');
     Serial.print(now.month(), DEC);
+
     Serial.print(now.month(), DEC); // Affichage MOIS
 
     Serial.print('/');
 
     Serial.print('/');
     Serial.print(now.day(), DEC);
+
     Serial.print(now.day(), DEC);   // Affichage JOUR
 
     Serial.print(' ');
 
     Serial.print(' ');
     Serial.print(now.hour(), DEC);
+
     Serial.print(now.hour(), DEC);   // Affichage HEURES
 
     Serial.print(':');
 
     Serial.print(':');
     Serial.print(now.minute(), DEC);
+
     Serial.print(now.minute(), DEC); // Affichage MINUTES
 
     Serial.print(':');
 
     Serial.print(':');
     Serial.print(now.second(), DEC);
+
     Serial.print(now.second(), DEC); // Affichage SECONDES
 
     Serial.println();</nowiki>
 
     Serial.println();</nowiki>
   −
There's pretty much only one way to get the time using the RTClib, which is to call '''now()''', a function that returns a DateTime object that describes the year, month, day, hour, minute and second when you called '''now()'''.
+
Il n'y a qu'une seule façon d'obtenir l'heure avec RTCLib, c'est d'appeler '''now()''', une fonction qui retourne un objet DateTime qui contient/décrit l'année (''year''), le mois (''month''), le jour (''day''), l'heure (''hour''), les minutes (''minute'') et secondes (''second'') au moment de l'appel de '''now()'''.
   −
There are some RTC libraries that instead have you call something like '''RTC.year()''' and '''RTC.hour()''' to get the current year and hour. However, there's one problem where if you happen to ask for the minute right at '''3:14:59''' just before the next minute rolls over, and then the second right after the minute rolls over (so at '''3:15:00''') you'll see the time as '''3:14:00''' which is a minute off. If you did it the other way around you could get '''3:15:59''' - so one minute off in the other direction.
+
'''Truc et astuce:'''
 +
 
 +
Il existe des librairie RTC qui permettent d'obtenir les différentes informations par l'intermédiaire de différentes fonctions "plus directes". Vous pouvez donc faire des appels comme '''RTC.year()''' ('''année''') et '''RTC.hour()''' ('''heure''') to get the current year and hour. However, there's one problem where if you happen to ask for the minute right at '''3:14:59''' just before the next minute rolls over, and then the second right after the minute rolls over (so at '''3:15:00''') you'll see the time as '''3:14:00''' which is a minute off. If you did it the other way around you could get '''3:15:59''' - so one minute off in the other direction.
    
Because this is not an especially unlikely occurance - particularly if you're querying the time pretty often - we take a 'snapshot' of the time from the RTC all at once and then we can pull it apart into '''day()''' or '''second()''' as seen above. Its a tiny bit more effort but we think its worth it to avoid mistakes!
 
Because this is not an especially unlikely occurance - particularly if you're querying the time pretty often - we take a 'snapshot' of the time from the RTC all at once and then we can pull it apart into '''day()''' or '''second()''' as seen above. Its a tiny bit more effort but we think its worth it to avoid mistakes!
29 879

modifications

Menu de navigation