Artificial Intelligence
Please fill the required field.

create an arduino code using rtc ds1302 with a 4 digit seven segment display.


#include <DS1302.h> // including the library for rtc ds1302 #include <SevSeg.h> // including the library for 4 digit seven segment display DS1302 rtc(2,3,4); // setting the rtc connections SevSeg display; // initializing the display //setting pins for the seven segment display #define LED_A 6 #define LED_B 7 #define LED_C 8 #define LED_D 9 #define LED_E 10 #define LED_F 11 #define LED_G 12 #define LED_DP 13 int currentHour, currentMinute, currentSecond; // function to convert from BCD to decimal int bcdToDec(int val) { return ( (val/16*10) + (val%16) ); } void setup() { pinMode(LED_A, OUTPUT); //setting up the data pins pinMode(LED_B, OUTPUT); pinMode(LED_C, OUTPUT); pinMode(LED_D, OUTPUT); pinMode(LED_E, OUTPUT); pinMode(LED_F, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_DP, OUTPUT); rtc.halt(false); //starting the rtc rtc.writeProtect(false); display.begin(COMMON_CATHODE,4,5,3,1,0); //starting the display display.setBrightness(100); //setting the level of brightness } void loop() { rtc.getTime(currentHour, currentMinute, currentSecond); //getting the time from the rtc int hour = bcdToDec(currentHour); //converting BCD to decimal values int minute = bcdToDec(currentMinute); int second = bcdToDec(currentSecond); //displaying the time display.setNumber(hour, 0); //setting the hour value to the first position display.setNumber(minute, 1); //setting the minute value to the second position display.setNumber(second, 2); //setting the second value to the third position display.setColon(true); //turning on the colon on the display //setting the number of cycles to display the time before updating the values for(int i=0; i<50; i++){ display.refreshDisplay(); //displaying the time delay(100); //delay for 100ms ( one second ) } }