Horloge1 Ino
Horloge1 Ino
Horloge1
pour 02- LILYGO TTGO T5 + 2.13" E-Paper Screen (250 x 122 px)
OK compilé avec type de carte = "ESP32 Dev Module"
**/
#include <stdint.h>
#include <GxEPD.h> // note: cette lib inclue la lib "Adafruit_GFX.h" dans laquelle
se trouvent les fonctions de base
#include "SPI.h"
#include <Wire.h>
#include "uRTCLib.h"
#include "DHT.h"
#include <WiFi.h>
#include <HTTPClient.h>
uRTCLib rtc(0x68);
#include "chiffres/60_75/chiffres60_75.c"
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#define SPI_MOSI 23
#define SPI_MISO -1
#define SPI_CLK 18
#define ELINK_SS 5
#define ELINK_BUSY 4
#define ELINK_RESET 16
#define ELINK_DC 17
#define SDCARD_SS 13
#define SDCARD_CLK 14
#define SDCARD_MOSI 15
#define SDCARD_MISO 2
//#define bouton1 39
//#define led1 12 //const int led1 = 12;
uint32_t start_time;
uint32_t next_time;
uint32_t previous_time;
uint32_t previous_full_update;
uint32_t memoM1 = 0;
uint32_t memoM2 = 0;
uint32_t currentMillis=0;
const uint32_t tempo1 = 2000; // 2000 ms = 2s
uint8_t annee;
uint8_t mois;
uint8_t jour;
uint8_t jour_de_la_semaine;
uint8_t heure=0;
uint8_t minute=0;
uint8_t memo_minute=0;
uint8_t seconde=0;
uint8_t annee_in=0;
uint8_t mois_in=0;
uint8_t jour_in=0;
uint8_t heures_in=0;
uint8_t minutes_in=0;
uint8_t secondes_in=0;
uint8_t W_chiffres = 60;
uint8_t H_chiffres = 75;
uint16_t box1_x = 0;
uint16_t box1_y = 0;
uint16_t box1_w = 249;
uint16_t box1_h = 110;
uint16_t box2_x = 0;
uint16_t box2_y = 121-20;
uint16_t box2_w = 175;
uint16_t box2_h = 20;
SPIClass sdSPI(VSPI);
uint8_t WiFi_status=0;
int connection_WiFi()
{
//Serial.println("Cnx Client WiFi");
WiFi.persistent(false);
WiFi.begin(ssid, password);
delay(2000);
uint8_t n=0;
while(WiFi.status() != WL_CONNECTED)
{
delay(500);
n++;
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setTextSize(1);
display.setCursor(0, display.height() -2);
display.print(".");
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
if (n>10) {return 1;}
// ECRAN_1.print(".");
//Serial.print(".");
}
//Serial.println("");
//Serial.print("Connected to WiFi - IP Address : ");
//Serial.println(WiFi.localIP());
//Serial.println("\n");
return 0;
}
void httpGetTime()
{
//Serial.println("envoi req Heure");
HTTPClient http1;
http1.begin(srvName_heure);
if (httpResponseCode>0)
{
recp_time = http1.getString();
}
http1.end();
}
void httpGetDate()
{
//Serial.println("envoi req Date");
HTTPClient http2;
http2.begin(srvName_date);
if (httpResponseCode>0)
{
recp_date = http2.getString();
}
http2.end();
}
void ajuste_time()
{
//Serial.println("ajuste_time");
//Serial.println( recp_time);
if(recp_time.length() == 8)
{
WiFi_status =1;
heures_in =(recp_time.substring(0,2)).toInt();
//Serial.print(heures_in); //Serial.print(":");
minutes_in =(recp_time.substring(3,5)).toInt();
//Serial.print(minutes_in); //Serial.print(":");
secondes_in =(recp_time.substring(6,8)).toInt();
//Serial.println(secondes_in);
//secondes_in++; // pour compenser le temps de traitement
void ajuste_date()
{
//Serial.println("ici7");
if(recp_date.length() == 8)
{
WiFi_status =1;
//Serial.println("ajuste_date");
//Serial.println( recp_date);
// String data_in = "01:02:21"
jour_in =(recp_date.substring(0,2)).toInt();
//Serial.println(jour_in);
mois_in =(recp_date.substring(3,5)).toInt();
//Serial.println(mois_in);
annee_in =(recp_date.substring(6,8)).toInt();
//Serial.println(annee_in);
void set_time_par_wifi()
{
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setTextSize(1);
int w1=connection_WiFi();
if (w1==0)
{
if(WiFi.status()== WL_CONNECTED )
{
//display.print("OK !");
delay(500);
httpGetDate();
ajuste_date();
display.print(recp_date);
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
delay(2000);
}
}
else
{
display.fillRect(box2_x, box2_y, box2_w, box2_h, GxEPD_WHITE);
display.setCursor(0, display.height() -2);
display.print("No WIfI");
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
smartdelay(1000);
display.fillRect(box2_x, box2_y, box2_w, box2_h, GxEPD_WHITE);
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
return ;
//---------------------------------------------------------------------
int w2=connection_WiFi();
if (w2==0)
{
if(WiFi.status()== WL_CONNECTED )
{
//display.print("OK !");
delay(500);
httpGetTime();
ajuste_time();
display.print(recp_time);
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
delay(2000); // pour éviter collision accès wifi
}
}
delay(1000);
incremente_heure(6); // pour compenser les delais de traitement
delay(500);
/*
display.fillRect(box2_x, box2_y, box2_w, box2_h, GxEPD_WHITE);
for(int8_t n =0; n<4; n++)
{
display.updateWindow(box2_x, box2_y, box2_w, box2_h, true);
}
*/
delay(100);
//display.update(); //full pour éviter de garder des moirages
//Serial.println("deconnexion WiFi");
WiFi.disconnect();
void Set_Time()
{
// appelée par appui sur le bouton (en bord de carte) après avoir correctement
paramétré ces données.
uint8_t second = 3;
uint8_t minute = 39;
uint8_t hour = 5;
uint8_t dayOfWeek = 4; // toutefois le jour de la semaine sera
recalculé plus bas, en temps réel
uint8_t dayOfMonth = 20;
uint8_t month = 1;
uint8_t year = 21; // 2021
void setup()
{
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
delay (1000);
pinMode(bouton1, INPUT);
pinMode(led1, OUTPUT);
//Serial.begin(115200);
//Serial.println("//Serial OK");
#ifdef ARDUINO_ARCH_ESP8266
URTCLIB_WIRE.begin(0, 2); // D3 and D4 on ESP8266
#else
URTCLIB_WIRE.begin();
#endif
display.init();
display.setRotation(1);
//display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold12pt7b);
display.setCursor(0, 0);
//esp_sleep_enable_ext0_wakeup((gpio_num_t)BUTTON_PIN, LOW);
display.fillScreen(GxEPD_WHITE);
//display.eraseDisplay();
display.update();
dht.begin();
Lit_RTC();
affichages();
//set_time_par_wifi();
//delay(1000);
//affichages();
}
switch (nb)
{
case 0: {display.drawBitmap(chiffre0, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 1: {display.drawBitmap(chiffre1, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 2: {display.drawBitmap(chiffre2, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 3: {display.drawBitmap(chiffre3, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 4: {display.drawBitmap(chiffre4, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 5: {display.drawBitmap(chiffre5, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 6: {display.drawBitmap(chiffre6, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 7: {display.drawBitmap(chiffre7, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 8: {display.drawBitmap(chiffre8, x0, y0, w0, h0, GxEPD_BLACK); }
break;
case 9: {display.drawBitmap(chiffre9, x0, y0, w0, h0, GxEPD_BLACK); }
break;
}
}
void affiche_heure()
{
display.fillRect(box1_x, box1_y, box1_w, box1_h, GxEPD_WHITE);
//display.setCursor(box1_x, cursor_y);
uint8_t x0 = box1_x;
uint8_t y0 = 5;
uint8_t heures_unites;
uint8_t heures_dizaines;
heures_unites = heure %10;
heures_dizaines = heure /10;
print_big_chiffre(heures_dizaines, x0, y0);
print_big_chiffre(heures_unites, x0+56, y0);
x0+=133;
uint8_t minutes_unites ;
uint8_t minutes_dizaines;
minutes_unites = minute %10;
minutes_dizaines = minute /10;
print_big_chiffre(minutes_dizaines, x0, y0);
print_big_chiffre(minutes_unites, x0+56, y0);
display.setCursor(106, 70);
display.setTextSize(3);
display.println(":");
void calcul_jour_de_la_semaine()
{
// d'après l'Algorithme de Mike Keith
uint16_t d, m, y, z, jds;
d=jour;
m=mois;
y=annee;
if (m>=3)
{
jds = ( ((23*m)/9) + d + 4 + y + (y/4) - (y/100) + (y/400) - 2 ) % 7;
}
else
{
z = y-1;
jds = ( ((23*m)/9) + d + 4 + y + (z/4) - (z/100) + (z/400) ) % 7;
}
jour_de_la_semaine = jds;
}
String conv_time(uint8_t t)
{
String r;
r=String(t);
if (t<10) {r="0"+r;}
return r;
}
void affiche_date()
{
String date;
calcul_jour_de_la_semaine();
switch (jour_de_la_semaine)
{
case 0: { date+="DIM ";} break;
case 1: { date+="LUN ";} break;
case 2: { date+="MAR ";} break;
case 3: { date+="MER ";} break;
case 4: { date+="JEU ";} break;;
case 5: { date+="VEN ";} break;
case 6: { date+="SAM ";} break;
}
switch (mois)
{
case 1: {date+="JAN"; } break;
case 2: {date+="FEV"; } break;
case 3: {date+="MARS";} break;
case 4: {date+="AVR"; } break;
case 5: {date+="MAI"; } break;
case 6: {date+="JUIN";} break;
case 7: {date+="JUIL";} break;
case 8: {date+="AOUT";} break;
case 9: {date+="SEPT";} break;
case 10: {date+="OCT"; } break;
case 11: {date+="NOV"; } break;
case 12: {date+="DEC"; } break;
}
date += " 20"+String(annee);
//date;
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setTextSize(1);
display.setCursor(0, display.height() -2);
display.print(date);
currentMillis = millis();
if (currentMillis > 2000) memoM1= currentMillis - 2000; // pour afficher
+rapidement au départ
void affiche_temperature(double T)
{
uint16_t y0 = 122; // position verticale du bord supérieur de la box
uint16_t dy = 34; // dimension verticale de la box
uint16_t box2_x = 180; // position horizontale du bord gauche de la box
uint16_t box2_y = y0-dy;
uint16_t box2_w = 65; // largeur de la box
uint16_t box2_h = dy;
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold12pt7b);
display.setTextSize(1,2);
display.setCursor(box2_x, y0-4);
display.print(T,1);
display.setFont(&FreeMonoBold9pt7b);
display.setTextSize(1);
display.setCursor(box2_x +30, display.height() -20);
display.print("o"); // le signe 'degré' (° Celsius en l'occurence) , absent
de la police de caractères
void affichages()
{
affiche_heure();
affiche_date();
float H1 = dht.readHumidity();
double T1 = dht.readTemperature(); // °C par defaut
//Serial.print(F("Temperature: ")); ////Serial.println(T1);
affiche_temperature(T1);
void Lit_RTC()
{
rtc.refresh();
annee=rtc.year();
mois=rtc.month();
jour=rtc.day();
jour_de_la_semaine=rtc.dayOfWeek();
heure = rtc.hour();
memo_minute = minute;
minute = rtc.minute();
seconde = rtc.second();
}
void loop()
{
bouton1_etat = digitalRead(bouton1);
if (bouton1_etat == 0)
{
Set_Time();
currentMillis = millis();
Lit_RTC();
if(minute != memo_minute)
{
affichages();
}
}
esp_light_sleep_start();
}