bonsoir
ci-joint le code de mon programme hebdomadaire
[#include "Wire.h"
#include "TM1637.h"
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
#define CLK 5
#define DIO 6
#define brightness 7
TM1637 tm1637(CLK,DIO);
#define DS3231_I2C_ADDRESS 0x68
// Initialize display 1
const byte PIN_CLK_D1 = 3; // define CLK pin (any digital pin)
const byte PIN_DIO_D1 = 4; // define DIO pin (any digital pin)
SevenSegmentTM1637 display2(PIN_CLK_D1, PIN_DIO_D1);
// Initialize display 2
const byte PIN_CLK_D2 = 12; // define CLK pin (any digital pin)
const byte PIN_DIO_D2 = 4; // define DIO pin (any digital pin)
SevenSegmentTM1637 display1(PIN_CLK_D2, PIN_DIO_D2);
volatile boolean flag;
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val){
return ( (val/16*10) + (val%16) );
}
void setDateDs3231(byte second,
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
//Wire.write(decToBcd(etat));
Wire.endTransmission();
}
void getDateDs3231(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void setup() {
Serial.begin(9600);
while (!Serial);
Wire.begin();
tm1637.init();
tm1637.set(brightness);
display2.begin(); // initializes the display
display2.setBacklight(100); // set the brightness to 100 %
delay(1000);// wait 1000 ms
display1.begin(); // initializes the display
display1.setBacklight(100); // set the brightness to 100 %
delay(1000);// wait 1000 ms
}
void loop(){
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs3231(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
int8_t TimeDisp[4];
TimeDisp[0] = hour / 10;
TimeDisp[1] = hour % 10;
TimeDisp[2] = minute / 10;
TimeDisp[3] = minute % 10;
tm1637.display(TimeDisp);
if(dayOfWeek ==1)
{
display2.print("0120");
display1.print("0340");
}
else if(dayOfWeek ==2)
{
display2.print("0220");
display1.print("0440");
}
else if(dayOfWeek ==3)
{
display2.print("0320");
display1.print("0540");
}
else if(dayOfWeek ==4)
{
display2.print("0420");
display1.print("0640");
}
else if(dayOfWeek ==5)
{
display2.print("0520");
display1.print("0740");
}
else if(dayOfWeek ==6)
{
display2.print("0620");
display1.print("0840");
} else if(dayOfWeek ==7)
{
display2.print("0720");
display1.print("0940");
}
}
]