Forum Controllers/PLC

Welcome!

This community is for professionals and enthusiasts of our products and services. Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

0

How to configure RTC in the included example?

Avatar
Amir

I can't find any documentation on how to use the RTC.h Library.

I am trying to use the RTC Library Example that is included when M-Duino board family is added.


This is my code:

// RTC library example

// by Industrial Shields


#include <RTC.h>

byte seconds = 0;

byte minutes = 50;

byte hours = 12;


/* Change these values to set the current initial date */

byte day = 4;

byte month = 8;

byte year = 20;


////////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {

  Serial.begin(9600L);


  RTC.setHour(hours);

  RTC.setMinute(minutes);

  RTC.setSecond(seconds);

  // Set the date

  RTC.setMonthDay(day);

  RTC.setMonth(month);

  RTC.setYear(year);

}


////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

 // if (!RTC.read()) {

 //   Serial.println("Read date error: is time set?");

 // } else {

 RTC.read();

    Serial.print("Time: ");

    Serial.print(RTC.getYear());

    Serial.print("-");

    Serial.print(RTC.getMonth());

    Serial.print("-");

    Serial.print(RTC.getMonthDay());

    Serial.print(" ");

    Serial.print(RTC.getHour());

    Serial.print(":");

    Serial.print(RTC.getMinute());

    Serial.print(":");

    Serial.print(RTC.getSecond());

    Serial.print(" (");

    Serial.print(RTC.getTime());

    Serial.println(")");

  


  delay(1000);

}

Avatar
Discard
3 Answers
0
Best Answer

Thank you Amir. It is very useful for me.

Avatar
Discard