#include <Wire.h>
#include <RTClib.h>
//#include <DS3231.h>
#include <SPI.h>
// 74HC595 11 CKL, 12 LATCH, 14 DATA
#define DATA_PIN 4
#define CLOCK_PIN 2
#define LATCH_PIN 3
#define AM_LED 11
#define PM_LED 12
#define COLON_LED 13
RTC_DS3231 rtc;
#define ADDRESS 0x68
byte monthChars[12][3] = {
{B01000111, B00001000, B01101010},
{B00111000, B00110000, B01100000},
{B00001001, B00001000, B01111010},
{B00001000, B00011000, B01111010},
{B00001001, B00001000, B01000100},
{B01000111, B01000001, B01101010},
{B01000111, B01000001, B01110001},
{B00001000, B01000001, B00000100},
{B00100100, B00110000, B00011000},
{B00000001, B00110001, B01110000},
{B01101010, B00000001, B01100011},
{B01000010, B00110000, B00110001}
};
byte segmentChars[] = {
B00000001,
B01001111,
B00010010,
B00000110,
B01001100,
B00100100,
B01100000,
B00001111,
B00000000,
B00001100
};
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
pinMode(AM_LED, OUTPUT);
pinMode(PM_LED, OUTPUT);
pinMode(COLON_LED, OUTPUT);
Wire.begin();
rtc.begin();
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
int year = now.year();
int month = now.month();
int day = now.day();
int hour24 = now.hour();
int hour = hour24 % 12;
if (hour == 0) hour = 12;
int minute = now.minute();
bool isPM = hour24 >= 12;
byte displayData[13];
for (int i = 0; i < 3; i++) {
displayData[i] = monthChars[month - 1][i];
}
displayData[3] = segmentChars[day / 10];
displayData[4] = segmentChars[day % 10];
displayData[5] = segmentChars[year / 1000];
displayData[6] = segmentChars[(year % 1000) / 100];
displayData[7] = segmentChars[(year % 100) / 10];
displayData[8] = segmentChars[year % 10];
displayData[9] = segmentChars[hour / 10];
displayData[10] = segmentChars[hour % 10];
displayData[11] = segmentChars[minute / 10];
displayData[12] = segmentChars[minute % 10];
digitalWrite(AM_LED, isPM);
digitalWrite(PM_LED, !isPM);
digitalWrite(COLON_LED, !(now.second() % 2 == 0));
updateDisplay(displayData);
delay(1000);
}
void updateDisplay(byte *data) {
digitalWrite(LATCH_PIN, LOW);
for (int i = 12; i >= 0; i--) {
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, data[i]);
}
digitalWrite(LATCH_PIN, HIGH);
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW
sevseg1:COM.1
sevseg1:COM.2
sevseg1:A
sevseg1:B
sevseg1:C
sevseg1:D
sevseg1:E
sevseg1:F
sevseg1:G
sevseg1:DP
sevseg2:COM.1
sevseg2:COM.2
sevseg2:A
sevseg2:B
sevseg2:C
sevseg2:D
sevseg2:E
sevseg2:F
sevseg2:G
sevseg2:DP
sevseg3:COM.1
sevseg3:COM.2
sevseg3:A
sevseg3:B
sevseg3:C
sevseg3:D
sevseg3:E
sevseg3:F
sevseg3:G
sevseg3:DP
sevseg4:COM.1
sevseg4:COM.2
sevseg4:A
sevseg4:B
sevseg4:C
sevseg4:D
sevseg4:E
sevseg4:F
sevseg4:G
sevseg4:DP
sevseg5:COM.1
sevseg5:COM.2
sevseg5:A
sevseg5:B
sevseg5:C
sevseg5:D
sevseg5:E
sevseg5:F
sevseg5:G
sevseg5:DP
sevseg6:COM.1
sevseg6:COM.2
sevseg6:A
sevseg6:B
sevseg6:C
sevseg6:D
sevseg6:E
sevseg6:F
sevseg6:G
sevseg6:DP
sevseg7:COM.1
sevseg7:COM.2
sevseg7:A
sevseg7:B
sevseg7:C
sevseg7:D
sevseg7:E
sevseg7:F
sevseg7:G
sevseg7:DP
sevseg8:COM.1
sevseg8:COM.2
sevseg8:A
sevseg8:B
sevseg8:C
sevseg8:D
sevseg8:E
sevseg8:F
sevseg8:G
sevseg8:DP
sevseg9:COM.1
sevseg9:COM.2
sevseg9:A
sevseg9:B
sevseg9:C
sevseg9:D
sevseg9:E
sevseg9:F
sevseg9:G
sevseg9:DP
sevseg10:COM.1
sevseg10:COM.2
sevseg10:A
sevseg10:B
sevseg10:C
sevseg10:D
sevseg10:E
sevseg10:F
sevseg10:G
sevseg10:DP
sevseg11:COM.1
sevseg11:COM.2
sevseg11:A
sevseg11:B
sevseg11:C
sevseg11:D
sevseg11:E
sevseg11:F
sevseg11:G
sevseg11:DP
sevseg12:COM.1
sevseg12:COM.2
sevseg12:A
sevseg12:B
sevseg12:C
sevseg12:D
sevseg12:E
sevseg12:F
sevseg12:G
sevseg12:DP
sevseg13:COM.1
sevseg13:COM.2
sevseg13:A
sevseg13:B
sevseg13:C
sevseg13:D
sevseg13:E
sevseg13:F
sevseg13:G
sevseg13:DP
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
led4:A
led4:C
sr1:Q1
sr1:Q2
sr1:Q3
sr1:Q4
sr1:Q5
sr1:Q6
sr1:Q7
sr1:GND
sr1:Q7S
sr1:MR
sr1:SHCP
sr1:STCP
sr1:OE
sr1:DS
sr1:Q0
sr1:VCC
r1:1
r1:2
r2:1
r2:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
r6:1
r6:2
r7:1
r7:2
sr2:Q1
sr2:Q2
sr2:Q3
sr2:Q4
sr2:Q5
sr2:Q6
sr2:Q7
sr2:GND
sr2:Q7S
sr2:MR
sr2:SHCP
sr2:STCP
sr2:OE
sr2:DS
sr2:Q0
sr2:VCC
r8:1
r8:2
r9:1
r9:2
r10:1
r10:2
r11:1
r11:2
r12:1
r12:2
r13:1
r13:2
r14:1
r14:2
sr3:Q1
sr3:Q2
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r13:DS
sr13:Q0
sr13:VCC
r85:1
r85:2
r86:1
r86:2
r87:1
r87:2
r88:1
r88:2
r89:1
r89:2
r90:1
r90:2
r91:1
r91:2
r92:1
r92:2
r93:1
r93:2
r94:1
r94:2
1
2
3
4
5
1
6
7
8
9
10
11
12
13
MONTH
DAY
YEAR
HOUR
MIN
AM
PM
PRESENT TIME