I succeed with this code !
/*
An open-source binary clock for Arduino.
Based on the code from by Rob Faludi (http://www.faludi.com)
Code under (cc) by Lucas Berbesson
http://creativecommons.org/license/cc-gpl
review to set time by Benwood
*/
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
// Init a Time-data structure
Time t;
int second = 0, minute = 0, hour = 0; //initialise la base de temps
int munit, hunit, minuteTens, hourTens, valm = 0, valh = 0, ledstats, i;
//Attribue les leds sur les differentes sorties
#define LED1 2
#define LED2 3
#define LED3 4
#define LED4 5
#define LED5 6
#define LED6 7
#define LED7 8
#define LED8 9
#define LED9 10
#define LED10 11
#define LED11 12
#define LED12 13
#define LED13 14 //A0
void setup() {
//set outputs
// Setup Serial connection
Serial.begin(115200);
// Initialize the rtc object
rtc.begin();
//
//
//
//HEURE A REGLER CI DESSOUS
//
//
//
//
rtc.setTime(22, 42, 30); // reglage de l'heure au format 12:00:00 (24hr format)
//
//
//
//
//
//
//
//
//
//
for (int k = 2; k <= 14; k++) {
pinMode(k, OUTPUT);
digitalWrite(k, LOW);
}
pinMode(A1, INPUT);
pinMode(A2, INPUT);
rtc.begin();
}
void loop() {
// Send time
Serial.println(rtc.getTimeStr());
t = rtc.getTime();
second = t.sec;
minute = t.min;
hour = t.hour;
munit = minute % 10; //sets the variable munit and hunit for the unit digits
hunit = hour % 10;
minuteTens = (int)(minute / 10);
hourTens = (int)(hour / 10);
//minutes units
if (munit & 1) {
digitalWrite(LED1, HIGH);
} else {
digitalWrite(LED1, LOW);
}
if (munit & 2) {
digitalWrite(LED2, HIGH);
} else {
digitalWrite(LED2, LOW);
}
if (munit & 4) {
digitalWrite(LED3, HIGH);
} else {
digitalWrite(LED3, LOW);
}
if (munit & 8) {
digitalWrite(LED4, HIGH);
} else {
digitalWrite(LED4, LOW);
}
//minutes
if (minuteTens & 1) {
digitalWrite(LED5, HIGH);
} else {
digitalWrite(LED5, LOW);
}
if (minuteTens & 2) {
digitalWrite(LED6, HIGH);
} else {
digitalWrite(LED6, LOW);
}
if (minuteTens & 4) {
digitalWrite(LED7, HIGH);
} else {
digitalWrite(LED7, LOW);
}
//hour units
if (hunit & 1) {
digitalWrite(LED8, HIGH);
} else {
digitalWrite(LED8, LOW);
}
if (hunit & 2) {
digitalWrite(LED9, HIGH);
} else {
digitalWrite(LED9, LOW);
}
if (hunit & 4) {
digitalWrite(LED10, HIGH);
} else {
digitalWrite(LED10, LOW);
}
if (hunit & 8) {
digitalWrite(LED11, HIGH);
} else {
digitalWrite(LED11, LOW);
}
//hour
if (hourTens & 1) {
digitalWrite(LED12, HIGH);
} else {
digitalWrite(LED12, LOW);
}
if (hourTens & 2) {
digitalWrite(LED13, HIGH);
} else {
digitalWrite(LED13, LOW);
}
valm = digitalRead(A1); // add one minute when pressed
if (valm == HIGH) {
minute++;
second = 0;
rtc.setTime(hour, minute, second);
delay(250);
}
valh = digitalRead(A2); // add one hour when pressed
if (valh == HIGH) {
hour++;
if (hour > 24) {
hour = 0;
}
second = 0;
rtc.setTime(hour, minute, second);
delay(250);
}
delay(50);
}
I would like to light on all the leds for 1 second at each new hour, can you please help ?