Voici le code à l'état brut ...
// VERSION 11 octobre AVEC ANNIVERSAIRES
// --------------- besoins pour affichage anniversaires
#include <SD.h>
#include <SPI.h>
File fichierAniv;
File fichierSSID;
static char buf[50];
int i;
int c;
int ligne = 0;
char *p1; // prenom
char *p2; // nom
char *p3; // jour
char *p4; // mois
char *p5; // année
char *p10; // SSISD
char *p11; // mot de passe
char *SSID;
char *MP;
// --------------- besoins pour affichage horloge
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int ledWIFI = 0;
int ledSD = 2;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset de l'OLED partagé avec l'Arduino (d'où la valeur à -1, et non un numéro de pin)
#define Oled_ADDRESS 0x3C // Adresse de "mon" écran OLED sur le bus i2c (généralement égal à 0x3C ou 0x3D)
Adafruit_SSD1306 ecranOLED(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // initialisation de l'écran avec le nom ecranOLED (à choisir)
//---------------- choix des polices
// Fonts est le nom du dossier dans lequel se trouvent tous les fonts de la bibliotheque Adafruit_GFX
#include <Fonts/FreeSans6pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
//---------------- besoins pour WIFI
#include <ESP8266WiFi.h>
const char *ssid = p10;
const char *password = p11;
int y;
String BUFFER_H;
//----------------- besoins pour internet
#include <EasyNTPClient.h>
#include <WiFiUdp.h>
#include <Timezone.h>
//------------------ besoins pour extraction données hors du WiFi
WiFiUDP Udp_G; // Objet UDP permettant d'envoyer et recevoir des trames Wi-Fi selon le protocole UDP
EasyNTPClient ClientNtp_G(Udp_G, "pool.ntp.org"); // Objet NTP synchronisé avec "pool.ntp.org"
TimeChangeRule RegleHeureEteFrance_G = { "RHEE", Last, Sun, Mar, 2, 120 }; // Règle de passage à l'heure d'été pour la France
TimeChangeRule RegleHeureHiverFrance_G = { "RHHE", Last, Sun, Oct, 3, 60 }; // Règle de passage à l'heure d'hiver la France
Timezone ConvertirHeureFrance_G(RegleHeureEteFrance_G, RegleHeureHiverFrance_G); // Objet de conversion d'heure avec les caractéristique de la métropole française
//------------------- matrice du logo Wifi
const unsigned char logoWIFI[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00,
0x3f, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xfc, 0x00, 0x03, 0xff, 0xff, 0xff, 0x00, 0x0f, 0xf8,
0x00, 0x7f, 0xc0, 0x1f, 0xc0, 0x00, 0x0f, 0xe0, 0x3f, 0x00, 0x00, 0x03, 0xf0, 0x7e, 0x03, 0xff,
0x01, 0xf8, 0x78, 0x1f, 0xff, 0xe0, 0x78, 0x70, 0x7f, 0xff, 0xf8, 0x38, 0x00, 0xff, 0xff, 0xfc,
0x00, 0x01, 0xfc, 0x00, 0xfe, 0x00, 0x03, 0xf0, 0x00, 0x3f, 0x00, 0x03, 0xc0, 0x00, 0x0f, 0x00,
0x03, 0x80, 0x38, 0x07, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x00,
0x1f, 0xff, 0xe0, 0x00, 0x00, 0x1f, 0x87, 0xe0, 0x00, 0x00, 0x1e, 0x01, 0xe0, 0x00, 0x00, 0x08,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0xfc,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00,
0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() { // exécuté 1 fois
// =========== PARTIE NECESSAIRE POUR HORLOGE ==============
pinMode(ledWIFI, OUTPUT);
pinMode(ledSD, OUTPUT);
digitalWrite(ledWIFI, LOW);
digitalWrite(ledSD, LOW);
Serial.begin(115200);
Wire.begin(4, 5);
sprintf(SSID, """,P10,""");
sprintf(MP, """,P11,""");
WiFi.begin(SSID, MP);
// --- initialisation oled
ecranOLED.begin(SSD1306_SWITCHCAPVCC, Oled_ADDRESS); // initialize with the I2C addr 0x3C
ecranOLED.clearDisplay(); // Vidange du buffer de l'écran OLED
// ========== PARTIE NECESSAIRE POUR ANNIVERSAIRES ===========
SPI.pins(14, 12, 13, 15); // SCK, MISO, MOSI, CS
// Ouverture du port série
Serial.begin(115200);
while (!Serial) {};
// Initialisation de la carte SD------------------------------
Serial.print("Initialisation de la carte SD ...");
if (!SD.begin(15)) {
Serial.println("initialisation echouee !");
digitalWrite(ledSD, LOW);
return;
}
Serial.println("initialisation reussie.");
digitalWrite(ledSD, HIGH);
//Ouverture du fichier csv anniversaires -----------------------------------
fichierAniv = SD.open("anniv.csv", FILE_READ);
//Lecture du fichier csv anniversaires -------------------------------------
while (fichierAniv.available()) {
for (i = 0; fichierAniv.available() && i < sizeof buf - 1; i++) {
buf[i] = fichierAniv.read();
if (buf[i] == '*')
break; // fin de ligne
}
buf[i] = 0; // fin de la chaine
//-séparation des données d'une ligne (ici 5 données max)-------------
p1 = strtok(buf, ";") ; // prenom
p2 = strtok(NULL, ";"); // nom
p3 = strtok(NULL, ";"); // jour
p4 = strtok(NULL, ";"); // mois
p5 = strtok(NULL, ";"); // années
//passage à la ligne suivante ----------------------------------
ligne++;
//--Verification de la lecture et du découpage anniversairees --------------
Serial.print(p1);
Serial.print(" ");
Serial.print(p2);
Serial.print(" ");
Serial.print(p3);
Serial.print(" ");
Serial.print(p4);
Serial.print(" ");
Serial.print(p5);
Serial.println("");
}
//Ouverture du fichier csv SSID -----------------------------------
fichierSSID = SD.open("SSID.csv", FILE_READ);
//Lecture du fichier csv SSID ------------------------------------
while (fichierSSID.available()) {
for (i = 0; fichierSSID.available() && i < sizeof buf - 1; i++) {
buf[i] = fichierSSID.read();
if (buf[i] == '*')
break; // fin de ligne
}
buf[i] = 0; // fin de la chaine
//-séparation des données d'une ligne (ici 5 données max)-------------
p10 = strtok(buf, ";"); // SSID
p11 = strtok(NULL, ";"); // mot de passe
//--Verification de la lecture et du découpage SSID --------------
Serial.print(p10);
Serial.print(" ");
Serial.print(p11);
Serial.println("");
//---- attente signal WiFi
unsigned long chrono = millis(); // remplace la fonction delai
while (millis() - chrono < 3000) yield();
while (WiFi.status() != WL_CONNECTED) {
affichagelogoWifi(); // appel sous-programme affichage logowifi clignotant
}
digitalWrite(ledWIFI, HIGH);
/*
// ---- detection si date d'anniversaire
f (AbreviationJour_L[weekday(Heure_P) - 1] = P3) &(AbreviationMois_L[month(Heure_P) - 1] = p4) {
Serial.println("anniversaire de Joseph");
}
*/
}
}
void loop() { // executé à l'infini
time_t HeureLocale_L;
HeureLocale_L = ConvertirHeureFrance_G.toLocal(ClientNtp_G.getUnixTime());
AfficherHeureLocale(HeureLocale_L);
}
//================ SOUS-PROGRAMME affichage logoWiFi
void affichagelogoWifi(void) {
//------------------ affichage logo WIFI
//drawBitmap(x position, y position, bitmap data, bitmap width, bitmap height, color)
ecranOLED.drawBitmap(50, 20, logoWIFI, 38, 32, WHITE); // dessin et position du logo placés dans le buffer
ecranOLED.display(); // affichage sur l'écran du contenu du buffer
unsigned long chrono = millis();
// chrono = millis(); // remplace la fonction delai
while (millis() - chrono < 600) yield(); // durée logo visible
//------------------ Extinction logo WIFI
ecranOLED.clearDisplay(); // dessin et position du logo placés dans le buffer
ecranOLED.display(); // affichage sur l'écran du contenu du buffer
chrono = millis(); // remplace la fonction delai
while (millis() - chrono < 300) yield(); //durée logo éteint
}
//=================== SOUS PROGRAMME centrage textes
void oledDisplayCenter(String text, int Y) {
int16_t x1;
int16_t y1;
uint16_t width;
uint16_t height;
ecranOLED.getTextBounds(text, 0, 0, &x1, &y1, &width, &height); // extraction de la longueur width du texte
ecranOLED.setCursor((SCREEN_WIDTH - width) / 2, Y); // (largeur écran - longueur du texte) / 2 donne le point de départ du texte
}
//===================SOUS PROGRAMME positionnementà droite des textes
void oledDisplayDroit(String text, int Y) {
int16_t x1;
int16_t y1;
uint16_t longueur;
uint16_t height;
ecranOLED.getTextBounds(text, 0, 0, &x1, &y1, &longueur, &height);
ecranOLED.setCursor((102 - longueur), Y);
ecranOLED.print(text); // text to display
}
// =============== SOUS PROGRAMME AFFICHAGE SUR ECRAN
void AfficherHeureLocale(time_t Heure_P) {
char BUFFER_H[50];
char BUFFER_H1[50];
char BUFFER_H2[50];
char BUFFER_J[50];
char BUFFER_D[50];
char AbreviationMois_L[12][10] = { "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre" };
char AbreviationJour_L[7][10] = { "Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi" };
//----- effacement buffer écran
ecranOLED.clearDisplay();
//------création buufer Date = texte affiché
sprintf(BUFFER_D, "%s - %d", AbreviationMois_L[month(Heure_P) - 1], year(Heure_P));
ecranOLED.setFont(&FreeSans6pt7b); //mois, année = petits caractères
ecranOLED.setTextColor(WHITE);
oledDisplayCenter(BUFFER_D, 10);
ecranOLED.print(BUFFER_D);
//----- création buffer Jour = texte affiché
sprintf(BUFFER_J, "%s %.2d", AbreviationJour_L[weekday(Heure_P) - 1], day(Heure_P)); // %.2d affiche (01) et %.d affiche ( 1)
ecranOLED.setFont(&FreeSansBold9pt7b); //jour et date = moyens caractères
ecranOLED.setTextColor(WHITE);
oledDisplayCenter(BUFFER_J, 30);
ecranOLED.print(BUFFER_J);
//----- création buffer heure-minutes = texte affiché
sprintf(BUFFER_H1, "%d:%.2d", hour(Heure_P), minute(Heure_P)); // creation et remplissage de la variable "BUFFER_H"... %d
ecranOLED.setFont(&FreeSansBold12pt7b); //heure et minutes = gros caracteres
ecranOLED.setTextColor(WHITE);
oledDisplayCenter(BUFFER_H1, 62);
ecranOLED.print(BUFFER_H1);
//----- création buffer seconde
sprintf(BUFFER_H2, "%2d", second(Heure_P)); // creation et remplissage de la variable "BUFFER_H"
ecranOLED.setFont(&FreeSans6pt7b);
ecranOLED.setTextColor(WHITE);
ecranOLED.setCursor(108, 62);
ecranOLED.print(BUFFER_H2);
//-------affichage buffer sur écran
ecranOLED.display();
}