Artificial Intelligence
Please fill the required field.

create me an arduino code for four digit seven segment display that works with DS1302 RTC.

/*Libraries*/ #include <DS1302.h> //include DS1302 library #include <SevenSegmentTM1637.h> //include TM1637 library /*Define Pins*/ DS1302 rtc(RTC_CE, RTC_IO, RTC_CLK); //RTC pins SevenSegmentTM1637 display(A3, A2); //seven segment display pins /*Global Variables*/ int current_hour = 0; //variable to store current hour int current_minute = 0; //variable to store current minute int previous_minute = 0; //variable to compare previous minute int current_second = 0; //variable to store current second int previous_second = 0; //variable to compare previous second /*Setup function*/ void setup() { rtc.halt(false); //un-halt RTC rtc.writeProtect(false); //deactivate write protection display.begin(); //initialize seven segment display display.setBacklight(100); //set display brightness } /*Loop function*/ void loop() { //read time from RTC current_hour = rtc.getHour(h, true); //get current hour with 12-hour format current_minute = rtc.getMinute(m, false); //get current minute current_second = rtc.getSecond(s, false); //get current second /*Display hour*/ if (current_hour == 0) { //if hour is 0 display.print("12"); //display 12 } else if (current_hour > 12) { //if hour is greater than 12 display.print(current_hour - 12); //display hour in 12-hour format } else { display.print(current_hour); //display hour } /*Display colon every other second*/ if (current_second % 2 == 0) { //if current second is even number display.print(":"); //display colon } else { display.print(); //hide colon } /*Display minute*/ if (current_minute < 10) { //if current minute is a single digit number (e.g. 09) display.print(current_minute, DEC, 0); //display minute with leading zero } else { display.print(current_minute); //display minute } /*Display second*/ if (current_second % 2 != 0) { //if current second is odd number display.setColon(true); //turn on display colon } else { display.setColon(false); //turn off display colon } delay(1000); //wait for 1 second }