#include <Wire.h> #include "RTClib.h" RTC_DS1307 rtc; byte segCode[10] = { // abcdefg B1111110, // 0 B0110000, // 1 B1101101, // 2 B1111001, // 3 B0110011, // 4 B1011011, // 5 B1011111, // 6 B1110000, // 7 B1111111, // 8 B1111011 // 9 }; byte symbols[2] = { B0000000, B0000100, // : }; // g f e d c b a d1 d2 d3 d4 d5(symbols) uint8_t pins[12] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; uint16_t digit1, digit2, digit3, digit4, colon; #define drivePinA A0 #define drivePinB A1 void setup() { for(int i = 0; i < 12; i++){ pinMode(pins[i], OUTPUT); // set all 12 pins in array pins[] as output pins digitalWrite(pins[i], HIGH); // set all 12 pins in array pins[] to HIGH state } pinMode(drivePinA, OUTPUT); pinMode(drivePinB, OUTPUT); digitalWrite(drivePinA, LOW); digitalWrite(drivePinB, LOW); delay(200); if (! rtc.begin()) { while (1); } if (! rtc.isrunning()) { // following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); } } void displaySeg(int dig1, int dig2, int dig3, int dig4, int colon){ int mask = 1; digitalWrite(pins[7], LOW); for(int i = 0; i < 7; i++){ if((mask & segCode[dig4] ) == 0) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); mask = mask << 1; } delay(1); mask = 1; digitalWrite(pins[7], HIGH); digitalWrite(pins[8], LOW); for(int i = 0; i < 7; i++){ if((mask & segCode[dig3]) == 0) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); mask = mask << 1; } delay(1); mask = 1; digitalWrite(pins[8], HIGH); digitalWrite(pins[9], LOW); for(int i = 0; i < 7; i++){ if((mask & segCode[dig2]) == 0) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); mask = mask << 1; } delay(1); mask = 1; digitalWrite(pins[9], HIGH); digitalWrite(pins[10], LOW); for(int i = 0; i < 7; i++){ if((mask & segCode[dig1]) == 0) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); mask = mask << 1; } delay(1); mask = 1; digitalWrite(pins[10], HIGH); digitalWrite(pins[11], LOW); for(int i = 0; i < 7; i++){ if((mask & symbols[colon]) == 0) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); mask = mask << 1; } delay(1); digitalWrite(pins[11], HIGH); } void loop() { DateTime now = rtc.now(); digit4 = now.minute(); digit3 = now.minute() * 0.1 ; digit2 = now.hour(); digit1 = now.hour() * 0.1 ; colon = now.second(); displaySeg( digit4 % 10, digit3 % 10, digit2 % 10, digit1 % 10, colon % 2 ); if(colon%2 ==0 ){ digitalWrite(drivePinA, HIGH); delay(1); digitalWrite(drivePinB, LOW); } else{ digitalWrite(drivePinA, LOW); delay(1); digitalWrite(drivePinB, HIGH); } } Schematics: https://youtu.be/zH_Xcykdv3s?t=99 Code: https://youtu.be/zH_Xcykdv3s?t=113
Cool & nice project! May I request you for code/sketch of this project, please?
Thanks!!!
@unrelatedactivities