Heure d'été/heure d'hiver automatique avec DS1307

Salut a tous je sais que ce sujet est déjà sorti sur le forum , mais il c'est arrêter en route donc j'aimerais le reprendre car j'ai aussi un problème avec le changement automatique d’heure été / hiver donc si quelqu'un a la bonté de m'aider

Cordialement

Bonjour,
Très joli tuto sur le DS1307.
:smiling_imp:

Oui effectivement , mais je n'arrive pas a trouver comment intégrer le changement automatique d'heure été / hiver .

Voici mon programme pour le moment :

#include <Wire.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00;

void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime();
}

void loop(){
printDate();
delay(1000);
}

void setDateTime(){
byte seconde = 00; //0-59
byte minute = 18; //0-59
byte heure = 9; //0-23
byte jour = 2; //1-7
byte monthDay = 27; //1-31
byte mois = 1; //1-12
byte annee = 15; //0-99
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.write(decToBcd(seconde));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(heure));
Wire.write(decToBcd(jour));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(mois));
Wire.write(decToBcd(annee));
Wire.write(zero); //start
Wire.endTransmission();

}

byte decToBcd(byte val) {
return ( (val/1016) + (val%10) ); }
byte bcdToDec(byte val) {
return ( (val/16
10) + (val%16) );}
void printDate(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
int seconde = bcdToDec(Wire.read());
int minute = bcdToDec(Wire.read());
int heure = bcdToDec(Wire.read() & 0b111111);
int jour = bcdToDec(Wire.read());
int monthDay = bcdToDec(Wire.read());
int mois = bcdToDec(Wire.read());
int annee = bcdToDec(Wire.read());
// 3/1/11 23:59:59
Serial.print(monthDay);
Serial.print("/");
Serial.print(mois);
Serial.print("/");
Serial.print(annee);
Serial.print(" ");
Serial.print(heure);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(seconde);

}

Qu'en pensez-vous ?

Re,
Tu le faits exprès.
A lire impérativement et Pour les balises "code"

J'utilise la fonction ci-dessous dont je n'arrive plus à retrouver la source ici. Elle m'avait été donné quand j'avais évoqué le sujet.

Elle prend en entrée un DateTime issu de la lib RTCLib pour DS1307.
L'heure dans le DS1307 est toujours en UTC et cette fonction retourne le nombre de secondes à y ajouter pour avoir l'heure locale.

J'utilise ça dans mes horloges, et c'est vraiment très pratique.

uint16_t adjustDstEurope(DateTime t)
{
 /*You can use the following equations to calculate when DST starts and ends.
 The divisions are integer divisions, in which remainders are discarded.
 "mod" means the remainder when doing integer division, e.g., 20 mod 7 = 6.
 That is, 20 divided by 7 is 2 and 6/7th (where six is the remainder).
 With: y = year.
        For the United States:
            Begin DST: Sunday April (2+6*y-y/4) mod 7+1
            End DST: Sunday October (31-(y*5/4+1) mod 7)
           Valid for years 1900 to 2006, though DST wasn't adopted until the 1950s-1960s. 2007 and after:
            Begin DST: Sunday March 14 - (1 + y*5/4) mod 7
            End DST: Sunday November 7 - (1 + y*5/4) mod 7;
        European Economic Community:
            Begin DST: Sunday March (31 - (5*y/4 + 4) mod 7) at 1h U.T.
            End DST: Sunday October (31 - (5*y/4 + 1) mod 7) at 1h U.T.
            Since 1996, valid through 2099
(Equations by Wei-Hwa Huang (US), and Robert H. van Gent (EC))
 
 Adjustig Time with DST Europe/France/Paris: UTC+1h in winter, UTC+2h in summer
 
 */
 
  // last sunday of march
  int beginDSTDate=  (31 - (5* t.year() /4 + 4) % 7);
  //Serial.println(beginDSTDate);
  int beginDSTMonth=3;
  //last sunday of october
  int endDSTDate= (31 - (5 * t.year() /4 + 1) % 7);
  //Serial.println(endDSTDate);
  int endDSTMonth=10;
  // DST is valid as:
  if (((t.month() > beginDSTMonth) && (t.month() < endDSTMonth))
      || ((t.month() == beginDSTMonth) && (t.day() > beginDSTDate)) 
	  || ((t.month() == beginDSTMonth) && (t.day() == beginDSTDate) && (t.hour() >= 1))
      || ((t.month() == endDSTMonth) && (t.day() < endDSTDate))
	  || ((t.month() == endDSTMonth) && (t.day() == endDSTDate) && (t.hour() < 1)))
  return 7200;      // DST europe = utc +2 hour (summer time)
  else return 3600; // nonDST europe = utc +1 hour (winter time)
}