1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
   | #include <RTClib.h> // https://github.com/adafruit/RTClib
RTC_DS3231 horloge;
DateTime noelProchain(2015, 12, 25, 0, 0, 0); // le 25/12/2015 à minuit
 
void determinationNoel()
{
  DateTime maintenant = horloge.now();
  DateTime lendemainDeNoelDeCetteAnnee(maintenant.year(), 12, 26, 0, 0, 0);
 
  if (maintenant >= lendemainDeNoelDeCetteAnnee) {
    noelProchain = DateTime(maintenant.year() + 1, 12, 25, 0, 0, 0);
  } else {
    noelProchain = DateTime(maintenant.year(), 12, 25, 0, 0, 0);;
  }
}
 
void affichageTempsRestant()
{
  DateTime maintenant = horloge.now();
 
  TimeSpan attente = noelProchain - maintenant;
  Serial.print(F("Noël est dans "));
  Serial.print(attente.days());
  Serial.print(F(" jour"));
  if (attente.days() > 1) Serial.write('s');
  Serial.print(F(", "));
  Serial.print(attente.hours());
  Serial.print(F(" heure"));
  if (attente.hours() > 1) Serial.write('s');
  Serial.print(F(", "));
  Serial.print(attente.minutes());
  Serial.print(F(" minute"));
  if (attente.minutes() > 1) Serial.write('s');
  Serial.print(F(" et "));
  Serial.print(attente.seconds());
  Serial.print(F(" seconde"));
  if (attente.seconds() > 1) Serial.write('s');
  Serial.println();
}
 
void setup() {
  Serial.begin(115200);
  if (! horloge.begin()) {
    Serial.println("Horloge absente");
    while (true);
  }
}
 
void loop() {
  determinationNoel();
  affichageTempsRestant();
  delay(1000);
} | 
Partager