// TECHATRONIC.COM
// LIBRARY TM1637Display
// https://github.com/avishorp/TM1637
// LIBRARY RTClib
// https://github.com/adafruit/RTClib
#include <RTClib.h>
#include <TM1637TinyDisplay.h>
// Define the connections pins for TM1637 4 digit 7 segment display
#define CLK 3
#define DIO 4
// Define the connections pin for DS3231 RTC Module
// SCL - A5
// SDA - A4
// VCC - VCC
// GNG - GND
// Create rtc and display object
RTC_DS3231 rtc;
TM1637TinyDisplay display = TM1637TinyDisplay(CLK, DIO);
void setup() {
// Initialize the Serial Monitor at 9600 baud rate
Serial.begin(9600);
// Initialize the LED
pinMode(LED_BUILTIN, OUTPUT);
// Make the light flash to Indicate it has started
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
// Wait for console opening
delay(3000);
// Check if RTC is connected correctly
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
while (1);
}
// Check if the RTC lost power and if so, set the time:
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
// The following line sets the RTC to the date & time this sketch was compiled:
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
// Set the display brightness (0-7):
display.setBrightness(5);
// Clear the display:
display.clear();
}
void loop() {
// Get current date and time
DateTime now = rtc.now();
// Create time format to display:
int displaytime = (now.hour() * 100) + now.minute();
// Print displaytime to the Serial Monitor
Serial.println("Time Now:");
Serial.println(displaytime);
// Display the current time in 24 hour format with leading zeros enabled and a center colon:
display.showNumberDec(displaytime, 0b11100000, true);
// Remove the following lines of code if you want a static instead of a blinking center colon:
delay(1000);
display.showNumberDec(displaytime, true); // Prints displaytime without center colon.
delay(1000);
}
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:CLK
sevseg1:DIO
sevseg1:VCC
sevseg1:GND