//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.
*/