//Include librarys
#include "SevSeg.h"
#include "RTClib.h"
//Sets up librarys
RTC_DS1307 rtc;
SevSeg sevseg;
//Colon blink pin
const int CLN = 13;
//Saves the mode of the colon
int CLNState = LOW;
//Variables for the blinking code
unsigned long previousMillis = 0;
const long interval = 500;
//void setup
void setup() {
//Colon pin output
pinMode(CLN, OUTPUT);
//change colon pinstate
digitalWrite(CLN, CLNState);
//Display date
byte numDigits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12,};
bool resistorsOnSegments = false;
byte hardwareConfig = COMMON_ANODE;
bool updateWithDelays = false;
bool leadingZeros = false;
bool disableDecPoint = false;
//Enters display data
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
updateWithDelays, leadingZeros, disableDecPoint);
sevseg.setBrightness(90);
//Checks for the RTC
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
//void loop
void loop() {
//Checks current time
DateTime now = rtc.now();
//Converts time to an int
int time = now.hour() * 100 + now.minute();
//Checks if the time is higher than 12 so the last number goes on and of acordingly
if(time > 999){
sevseg.setNumber(time, 3);
}
else{
sevseg.setNumber(time, 2);
}
//Refresh the display
sevseg.refreshDisplay();
//variable for the blinking
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {//Delays the change
previousMillis = currentMillis;//Reset the counter
if (CLNState == LOW)
{
CLNState = HIGH;//Change the state to HIGH if its LOW
} else
{
CLNState = LOW;//Change the state to LOW if its HIGH
}
digitalWrite(CLN, CLNState);//Changes the colon for real
}
}
//nice
/*
This is just a normal digital clock.
It turns the hour digit of if the hour isn´t a double digit.
It keeps the time if the battery runs out but the display turns off.
If you add a new battery it will still have the time and you won´t have to set the time again.
*/
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
display:A
display:B
display:C
display:D
display:E
display:F
display:G
display:DP
display:DIG1
display:DIG2
display:DIG3
display:DIG4
display:COM
display:CLN
ds1307:GND
ds1307:5V
ds1307:SDA
ds1307:SCL
ds1307:SQW