RTC alarm
What this example shows
Set the time, the date and an alarm on the onboard PCF85063A real-time clock (RTC), then show the time once a minute and print ALARM! when the alarm has fired. The alarm is set one minute after the start time.
Example code
#include "Inkplate.h" // Include Inkplate library to the sketch
Inkplate inkplate; // Create an object on Inkplate library
// Set clock
uint8_t hour = 12;
uint8_t minutes = 51;
uint8_t seconds = 10;
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 means Monday, ...)
uint8_t weekday = 1;
uint8_t day = 20;
uint8_t month = 7;
uint8_t year = 26;
// Set alarm time and date (alarm will be generated 60 seconds after board power up)
uint8_t alarmHour = 12;
uint8_t alarmMinutes = 52;
uint8_t alarmSeconds = 10;
uint8_t alarmWeekday = 1;
uint8_t alarmDay = 20;
void setup()
{
inkplate.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
inkplate.rtc.reset(); // reset RTC if there is some data in it
inkplate.clearDisplay(); // Clear frame buffer of display
inkplate.setTextSize(3); // Set text to be 3 times bigger than classic 5x7 px text
inkplate.setTextColor(INKPLATE_RED, INKPLATE_WHITE); // Set text color and background
inkplate.rtc.setTime(hour, minutes, seconds); // Send time to RTC
inkplate.rtc.setDate(weekday, day, month, year); // Send date to RTC
inkplate.rtc.setAlarm(alarmSeconds, alarmMinutes, alarmHour, alarmDay, alarmWeekday); // Set alarm
}
void loop()
{
inkplate.rtc.getRtcData(); // Get the time and date from RTC
seconds = inkplate.rtc.getSecond(); // Store senconds in a variable
minutes = inkplate.rtc.getMinute(); // Store minutes in a variable
hour = inkplate.rtc.getHour(); // Store hours in a variable
day = inkplate.rtc.getDay(); // Store day of month in a variable
weekday = inkplate.rtc.getWeekday(); // Store day of week in a variable
month = inkplate.rtc.getMonth(); // Store month in a variable
year = inkplate.rtc.getYear(); // Store year in a variable
inkplate.clearDisplay(); // Clear content in frame buffer
inkplate.setCursor(100, 300); // Set position of the text
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
if (inkplate.rtc.checkAlarmFlag()) // Check if alarm has occurred
{
inkplate.rtc.clearAlarmFlag(); // It's recommended to clear alarm flag after alarm has occurred
inkplate.setCursor(400, 400); // Set new position for cursor
inkplate.print("ALARM!");
}
inkplate.display(); // Do a full refresh
delay(60000); // Delay between refreshes one minute
}
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint16_t _month,
uint8_t _year)
{
// Write time and date info on screen
char *wday[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
print2Digits(_hour);
inkplate.print(':');
print2Digits(_minutes);
inkplate.print(':');
print2Digits(_seconds);
inkplate.print(' ');
inkplate.print(wday[_weekday]);
inkplate.print(", ");
print2Digits(_day);
inkplate.print('/');
print2Digits(_month);
inkplate.print('/');
inkplate.print(_year, DEC);
}
void print2Digits(uint8_t _d)
{
if (_d < 10)
inkplate.print('0');
inkplate.print(_d, DEC);
}
The sketch stores the year as 26, but rtc.setDate() expects the full year and subtracts 2000 from it, and rtc.getYear() returns the full year. So the year on the screen will not read 2026. To get the right year, pass the full year (for example 2026) to setDate() in a uint16_t variable.
Functions used
Inkplate()returns NoneCreates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.
ReturnsConstructor; no return value.
inkplate.begin()returns voidInitializes the library, the peripherals and the frame buffer. Call it once in setup().
ReturnsNothing.
inkplate.rtc.reset()returns voidWrites the default value to the RTC's first control register, clearing settings left from an earlier sketch.
ReturnsNothing.
inkplate.clearDisplay()returns voidFills the frame buffer with white. It does not change the panel.
ReturnsNothing.
inkplate.setTextSize(uint8_t s)returns voidSets the text magnification, here 3.
ReturnsNothing.
inkplate.setTextColor(uint16_t c, uint16_t bg)returns voidSets the text color and the background color drawn behind each character, here red on white.
ReturnsNothing.
inkplate.rtc.setTime(uint8_t hour, uint8_t minute, uint8_t sec, bool isPM = false)returns voidWrites the time to the RTC. isPM is only used in 12-hour mode.
ReturnsNothing.
inkplate.rtc.setDate(uint8_t weekday, uint8_t day, uint8_t month, uint16_t yr)returns voidWrites the date to the RTC and marks it as set. Weekday 0 is Sunday. yr is the full year; the function subtracts 2000 before writing it.
ReturnsNothing.
inkplate.rtc.setAlarm(uint8_t alarm_second, uint8_t alarm_minute, uint8_t alarm_hour, uint8_t alarm_day, uint8_t alarm_weekday)returns voidSets the alarm time and enables the alarm.
ReturnsNothing.
inkplate.rtc.getRtcData()returns voidReads the time and date from the RTC; the get functions below return the values it read.
ReturnsNothing.
inkplate.rtc.getSecond()returns uint8_tReturns the seconds.
ReturnsSeconds.
inkplate.rtc.getMinute()returns uint8_tReturns the minutes.
ReturnsMinutes.
inkplate.rtc.getHour()returns uint8_tReturns the hours.
ReturnsHours.
inkplate.rtc.getDay()returns uint8_tReturns the day of the month.
ReturnsDay of the month.
inkplate.rtc.getWeekday()returns uint8_tReturns the day of the week, 0 (Sunday) to 6.
ReturnsDay of the week.
inkplate.rtc.getMonth()returns uint8_tReturns the month.
ReturnsMonth, 1 to 12.
inkplate.rtc.getYear()returns uint16_tReturns the year: the value stored in the RTC plus 2000.
ReturnsFull year.
inkplate.rtc.checkAlarmFlag()returns boolReports whether the alarm has fired.
Returnstrue once the alarm time is reached.
inkplate.rtc.clearAlarmFlag()returns voidClears the alarm flag so the next alarm can be detected.
ReturnsNothing.
inkplate.setCursor(int16_t x, int16_t y)returns voidSets where the next printed text starts.
ReturnsNothing.
inkplate.print(value, format)returns size_tPrints text, a character or a number into the frame buffer, like Serial.print(). DEC prints a number in decimal.
ReturnsNumber of bytes printed.
inkplate.display(bool _leaveOn = 0)returns voidSends the whole frame buffer to the panel and refreshes it.
ReturnsNothing.
What to expect
Once a minute the screen refreshes with the time and date in red, in the form HH:MM:SS Weekday, DD/MM/ followed by the year, starting at 12:51:10 Monday, 20/07/. On the refresh after the alarm time, ALARM! appears lower on the screen. The sketch prints nothing to the Serial Monitor.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/RTC/Inkplate7SPECTRA_RTC_Alarm