mardi 16 juillet 2019

Arduino Episode 19 : Projet Reveil (tout va bien)

Arduino Episode 19 : Projet Reveil (tout va bien)

J'ajoute juste mon code où le superflu est supprimé, et les effets me conviennent.
Prochaine étape : Le tilt

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <stdint.h>

RTC_DS3231 rtc;
char str [20];
char joursemaine[12];
char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
char jourmois[12];
char anneefull[4];
char horaire[12];

#define HARDWARE_TYPE MD_MAX72XX::ICSTATION_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
int j = 0;

void setup () {
P.begin();
P.setIntensity(0);
Serial.begin(9600);
delay(3000); // wait for console opening

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
rtc.adjust(DateTime(2019, 7, 15, 10, 01, 0));
}
}

void loop () {
DateTime now = rtc.now();

int anneefull = now.year();
int annee= (now.year()-2000);
int mois = now.month();
int jour = now.day();
int heure = now.hour();
int minutes = now.minute();

if (P.displayAnimate())
{
sprintf(joursemaine,daysOfTheWeek[now.dayOfTheWeek()]);
sprintf(jourmois,"%02d/%02d",jour,mois);
sprintf(anneefull,"%02d",anneefull);
sprintf(horaire,"%02d:%02d",heure,minutes);

switch (j) {
case 0:
P.displayText(joursemaine, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 1:
P.displayText(jourmois, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 2:
P.displayText(anneefull, PA_CENTER, 25 , 2000, PA_DISSOLVE, PA_DISSOLVE);
break;
case 3:
P.displayText(horaire, PA_CENTER, 25 , 30000, PA_DISSOLVE, PA_DISSOLVE);
break;
default:
break;
}
j = j + 1;
if (j > 5) j = 0;
}

Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.day(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(j);
Serial.println();
}

Aucun commentaire:

Enregistrer un commentaire