//SimpleClock
//by Myth! 
 
// This code controls a TM1637-based LED display to show the current time 
// obtained from a DS1307 real-time clock (RTC). 

#include <RTClib.h>  
#include <TM1637.h>   

#define CLK_PIN 2     // Pin connected to the CLK (clock) input of the LED display
#define DIO_PIN 3     // Pin connected to the DIO (data) input of the LED display

RTC_DS1307 rtc;       // Object for interacting with the DS1307 real-time clock
TM1637 display(CLK_PIN, DIO_PIN);  // Object for controlling the TM1637 LED display

void setup() {
  display.set(BRIGHT_TYPICAL);  // Set the LED display brightness to a typical level
  if (!rtc.begin()) {           // Initialize the real-time clock
    while (1);                  // Hang here indefinitely if RTC initialization fails
  }
  if (!rtc.isrunning()) {       // If the RTC is not running (e.g., due to power loss)
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));  // Set the RTC to the compile time
  }
}

void loop() {
  DateTime now = rtc.now();     // Get the current date and time from the RTC
  if (now.second() % 2 == 0) {  // Toggle the colon on the display every second
    display.point(POINT_ON);    // Turn on the colon
  } else {
    display.point(POINT_OFF);   // Turn off the colon
  }
  // Display the hour (with leading zero if necessary) on the first two digits
  display.display(0, now.hour() < 10 ? 0 : now.hour() / 10);
  display.display(1, now.hour() % 10);
  // Display the minute (with leading zero if necessary) on the last two digits
  display.display(2, now.minute() < 10 ? 0 : now.minute() / 10);
  display.display(3, now.minute() % 10);
}
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
4-Digit Display
sevseg1:CLK
sevseg1:DIO
sevseg1:VCC
sevseg1:GND
GND5VSDASCLSQWRTCDS1307+
rtc1:GND
rtc1:5V
rtc1:SDA
rtc1:SCL
rtc1:SQW