SHARE
TWEET

Testing RTC

jmyean May 17th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This code is to use with DS1302 RTC module, it permits you to setup the actual time and date
  2. //And you can visualize them on the serial monitor
  3. //This code is a modified version of the code provided in virtuabotixRTC library
  4. //Refer to Surtrtech Youtube chhannel/Facebook page for more information
  5.  
  6.  
  7.  
  8.  
  9. #include <virtuabotixRTC.h> //Library used
  10. virtuabotixRTC myRTC(4, 3, 2);
  11.  
  12. void setup() {
  13.  Serial.begin(9600);
  14.  
  15. // Set the current date, and time in the following format:
  16.  // seconds, minutes, hours, day of the week, day of the month, month, year
  17.  //myRTC.setDS1302Time(15, 22, 21, 7, 14, 1, 2018); //Here you write your actual time/date as shown above
  18.  //but remember to "comment/remove" this function once you're done
  19.  //The setup is done only one time and the module will continue counting it automatically
  20. }
  21.  
  22. void loop() {
  23.  // This allows for the update of variables for time or accessing the individual elements.
  24.  myRTC.updateTime();
  25.  
  26. // Start printing elements as individuals
  27.  Serial.print("Current Date / Time: ");
  28.  Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
  29.  Serial.print("/");
  30.  Serial.print(myRTC.month);
  31.  Serial.print("/");
  32.  Serial.print(myRTC.year);
  33.  Serial.print(" ");
  34.  Serial.print(myRTC.hours);
  35.  Serial.print(":");
  36.  Serial.print(myRTC.minutes);
  37.  Serial.print(":");
  38.  Serial.println(myRTC.seconds);
  39.  
  40. // Delay so the program doesn't print non-stop
  41.  delay(1000);
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top