/Seeed_Arduino_RTC

When your project needs to be unplugged, how to keep the time counting? This library can help you set up the current time.

Primary LanguageC++MIT LicenseMIT

Seeed_Arduino_RTC Build Status

Introduction

Seeed Arduino RTC is a Arduino library for RTC Moudle. At present, samd21 is supported and samd51 has built-in RTC module.

How to install Arduino Library

please refer here.

Usage

#include "RTC_SAMD21.h"
#include "DateTime.h"

RTC_SAMD21 rtc;
void setup()
{
    rtc.begin();

    Serial.begin(115200);

    while (!Serial)
    {
        ;
    }
    
    DateTime now = DateTime(F(__DATE__), F(__TIME__));
    Serial.println("adjust time!");
    rtc.adjust(now);

    now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

}
void loop()
{
    now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

}

API Reference

  • begin(void) : bool
rtc.begin()
  • now(void) : DateTime
DateTime now = rtc.now();
  • adjust(const DateTime) : void
DateTime now = DateTime(F(__DATE__), F(__TIME__));
rtc.adjust(now);
DateTime now = DateTime(2020, 7, 15, 0, 0, 0);
rtc.adjust(now);
  • setAlarm(const DateTime) : void
DateTime alarm = DateTime(2020, 7, 15, 18, 0, 0);
rtc.setAlarm(now);
  • alarm(void) : DateTime
DateTime now = rtc.alarm();
  • disableAlarm(uint8_t) : void
rtc.disableAlarm(0);
  • enableAlarm(uint8_t) : void
rtc.enableAlarm(0);
  • attachInterrupt(rtcCallBack) : void
rtc.attachInterrupt(rtcCallBack);
  • detachInterrupt(void) : void
rtc.detachInterrupt();

License

This software is written by seeed studio
and is licensed under The MIT License. Check License.txt for more information.

Contributing to this software is warmly welcomed. You can do this basically by
forking, committing modifications and then pulling requests (follow the links above
for operating guide). Adding change log and your contact into file header is encouraged.
Thanks for your contribution.

Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
Benefiting from local manufacture power and convenient global logistic system,
we integrate resources to serve new era of innovation. Seeed also works with
global distributors and partners to push open hardware movement.