RTC clock
What this example shows
Set the time and the date on the onboard PCF85063A real-time clock (RTC), read them back and show them on the screen. The screen refreshes once a minute.
Example code
#include "Inkplate.h" // Include Inkplate library to the sketch
Inkplate inkplate; // Create an object on Inkplate library
#define REFRESH_DELAY 60000 // Delay between refreshes one minute
unsigned long time1; // Time for measuring refresh in millis
// Set clock
uint8_t hour = 13;
uint8_t minutes = 0;
uint8_t seconds = 10;
// Set date and weekday (NOTE: In weekdays 0 means Sunday, 1 means Monday, ...)
uint8_t weekday = 1;
uint8_t day = 2;
uint8_t month = 2;
uint8_t year = 26;
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_BLACK, 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
getAndDisplayTime(); // Display time on the screen
}
void loop()
{
// Refresh screen every one minute
if ((unsigned long)(millis() - time1) > REFRESH_DELAY)
{
// Display time on the screen
getAndDisplayTime();
// Store current millis
time1 = millis();
}
}
void getAndDisplayTime()
{
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(80, 300); // Set position of the text
printTime(hour, minutes, seconds, day, weekday, month, year); // Print the time on screen
inkplate.display(); // Refresh the screen
}
void printTime(uint8_t _hour, uint8_t _minutes, uint8_t _seconds, uint8_t _day, uint8_t _weekday, uint8_t _month,
uint16_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 black 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.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.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
The screen shows the time and date in black in the form HH:MM:SS Weekday, DD/MM/ followed by the year, starting at 13:00:10 Monday, 02/02/, and refreshes with the current time once a minute. The sketch prints nothing to the Serial Monitor.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/RTC/Inkplate7SPECTRA_RTC_Simple