Epoch time convertor: www.epochconverter.com/ #include #include #define TIME_HEADER "T" // Header tag for serial time sync message #define TIME_REQUEST 7 // ASCII bell character requests a time sync message const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; int buttonApin = 9; int buttonBpin = 8; int r; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); void setup() { lcd.begin(16, 2); Serial.begin(9600); pinMode(buttonApin, INPUT_PULLUP); pinMode(buttonBpin, INPUT_PULLUP); while (!Serial) ; // Needed for Leonardo only pinMode(13, OUTPUT); setSyncProvider(requestSync); // Set function to call when sync required Serial.println("Waiting for sync message"); lcd.print("Loading....."); } void loop() { if (Serial.available()) { processSyncMessage(); } if (timeStatus() != timeNotSet) { digitalClockDisplay(); } if (timeStatus() == timeSet) { digitalWrite(13, HIGH); // LED on if synced } else { digitalWrite(13, LOW); // LED off if needs refresh } // Button handling if (digitalRead(buttonApin) == LOW) { adjustTime(3600); // Add 3600 seconds (1 hour) to the time delay(200); // Debounce delay } if (digitalRead(buttonBpin) == LOW) { adjustTime(60); // Add 60 seconds (1 minute) to the time delay(200); // Debounce delay } delay(1000); lcd.setCursor(0, 0); } void digitalClockDisplay() { lcd.print("Time "); if (hour() == 12 || hour() == 0 || hour() == 24) { lcd.print("12"); } else if (hour() > 9) { r = hour() % 12; if (r < 10) { lcd.print("0"); } lcd.print(r); Serial.print(hour() % 12); } else { lcd.print("0"); lcd.print(hour()); Serial.print(hour()); } // Display AM or PM printDigits(minute()); printDigits(second()); if (hour() < 12) { lcd.print(" AM"); } else { lcd.print(" PM"); } lcd.setCursor(0, 1); lcd.print("Date "); lcd.print(month()); lcd.print("/"); lcd.print(day()); lcd.print("/"); lcd.print(year()); Serial.print(" "); Serial.print(day()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(year()); Serial.println(); } void printDigits(int digits) { lcd.print(":"); if (digits < 10) lcd.print('0'); lcd.print(digits); } void processSyncMessage() { unsigned long pctime; const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 if (Serial.find(TIME_HEADER)) { pctime = Serial.parseInt(); if (pctime >= DEFAULT_TIME) { setTime(pctime); // Sync Arduino clock to the time received on the serial port } } } time_t requestSync() { Serial.write(TIME_REQUEST); return 0; // The time will be sent later in response to a serial message }
@manjuyadav-ws4xd11 ай бұрын
You deserve clout😢
@Waiduino11 ай бұрын
Yea I’m really hoping my channel will start growing a ton! Overall I just enjoy people watching my content to see the things I make and possibly make it themselves. But in any case, I am so thankful for all of my subscribers, especially you for commenting and your compliment. Thank you