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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
| //Librairies
#include <Arduino.h>
#include "decodeurDCF77.h"
#include <Wire.h>//https://www.arduino.cc/en/reference/wire
#include <DS3231.h>//https://github.com/NorthernWidget/DS3231
//Variables
const uint8_t PIN_DCF77 = 3;
boolean DATE_DCF77 = false;
byte ESSAI_DCF77 = 0;
byte JOUR_DCF77 = 0;
byte Year ;
byte Month ;
byte Date ;
byte DoW ;
byte Hour ;
byte Minute ;
byte Second ;
bool Century = false;
bool h12 ;
bool PM ;
//Objets
DS3231 Clock;
//Initialisation
void setup()
{
pinMode(PIN_DCF77, INPUT);
Serial.begin(115200);
DATE_DCF77 = false;
Serial.print("Initialisation");
//Wire.begin();
}
//Programme principal
void loop()
{
//Mise à jour de la date et de l'heure si
if (DATE_DCF77 = true)
{
Serial.println("Maj de la date");
Maj_Date();
}
}
//Fonctions
void Maj_Date()
{
//Le booléen passe à faux
DATE_DCF77 = false;
//Boucle de x cycles avec sortie si DCF77 = true
while (ESSAI_DCF77 < 10)
{
static uint8_t longueur = 0;
bool trame_decodee = decodeurDCF77.traiterSignal(digitalRead(PIN_DCF77), millis());
if (trame_decodee)
{
Serial.print(' ');
//Serial_printDCF77();
DATE_DCF77 = true;
JOUR_DCF77 = decodeurDCF77.jour();
Serial.print("Oui:");
Serial.print(JOUR_DCF77);
//break;
}
if (longueur > decodeurDCF77.longueur_trame_en_cours())
{
longueur = 0;
Serial.println();
//ESSAI_DCF77 = ESSAI_DCF77 + 1;
Serial.print("Nombre d'essai :");
Serial.print(ESSAI_DCF77);
Serial.println();
}
while (longueur < decodeurDCF77.longueur_trame_en_cours())
{
Serial.print(decodeurDCF77.bit_trame(longueur++));
}
}
}
void setDate( ) { /* function setDate */
////Set Real Time Clock
if (Serial.available()) {
//int _start = millis();
GetDateStuff(Year, Month, Date, DoW, Hour, Minute, Second);
Clock.setClockMode(false); // set to 24h
Clock.setSecond(Second);
Clock.setMinute(Minute);
Clock.setHour(Hour);
Clock.setDate(Date);
Clock.setMonth(Month);
Clock.setYear(Year);
Clock.setDoW(DoW);
}
}
void GetDateStuff(byte& Year, byte& Month, byte& Day, byte& DoW, byte& Hour, byte& Minute, byte& Second) { /* function GetDateStuff */
////Get date data
// Call this if you notice something coming in on
// the serial port. The stuff coming in should be in
// the order YYMMDDwHHMMSS, with an 'x' at the end.
boolean GotString = false;
char InChar;
byte Temp1, Temp2;
char InString[20];
byte j = 0;
while (!GotString) {
if (Serial.available()) {
InChar = Serial.read();
InString[j] = InChar;
j += 1;
if (InChar == 'x') {
GotString = true;
}
}
}
Serial.println(InString);
// Read Year first
Temp1 = (byte)InString[0] - 48;
Temp2 = (byte)InString[1] - 48;
Year = Temp1 * 10 + Temp2;
// now month
Temp1 = (byte)InString[2] - 48;
Temp2 = (byte)InString[3] - 48;
Month = Temp1 * 10 + Temp2;
// now date
Temp1 = (byte)InString[4] - 48;
Temp2 = (byte)InString[5] - 48;
Day = Temp1 * 10 + Temp2;
// now Day of Week
DoW = (byte)InString[6] - 48;
// now Hour
Temp1 = (byte)InString[7] - 48;
Temp2 = (byte)InString[8] - 48;
Hour = Temp1 * 10 + Temp2;
// now Minute
Temp1 = (byte)InString[9] - 48;
Temp2 = (byte)InString[10] - 48;
Minute = Temp1 * 10 + Temp2;
// now Second
Temp1 = (byte)InString[11] - 48;
Temp2 = (byte)InString[12] - 48;
Second = Temp1 * 10 + Temp2;
} |