diff --git a/CH32V203_eInk_Calendar_Clock/.none.test.only b/CH32V203_eInk_Calendar_Clock/.none.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/CH32V203_eInk_Calendar_Clock/CH32V203-eInk-Calendar-Clock.bin b/CH32V203_eInk_Calendar_Clock/CH32V203-eInk-Calendar-Clock.bin new file mode 100644 index 000000000..459c7c8de Binary files /dev/null and b/CH32V203_eInk_Calendar_Clock/CH32V203-eInk-Calendar-Clock.bin differ diff --git a/CH32V203_eInk_Calendar_Clock/CH32V203_eInk_Calendar_Clock.ino b/CH32V203_eInk_Calendar_Clock/CH32V203_eInk_Calendar_Clock.ino new file mode 100644 index 000000000..cb84a6a90 --- /dev/null +++ b/CH32V203_eInk_Calendar_Clock/CH32V203_eInk_Calendar_Clock.ino @@ -0,0 +1,100 @@ +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include +#include +#include "Adafruit_TinyUSB.h" +#include "Adafruit_ThinkInk.h" +#include "RTClib.h" +#include +#include +#include +#include + +#define EPD_DC PA3 +#define EPD_CS PA2 +#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay) +#define SRAM_CS PA1 +#define EPD_RESET -1 // can set to -1 and share with microcontroller Reset! +#define EPD_SPI &SPI // primary SPI + +// 1.54" Monochrome displays with 200x200 pixels and SSD1681 chipset +ThinkInk_154_Mono_D67 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY, EPD_SPI); + +RTC_DS3231 rtc; + +char daysOfTheWeek[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; +char monthsOfYear[13][4] = {"NULL", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; + +bool start = true; + +String lastTimeStr = "00:00"; + +void setup() { + Serial.begin(115200); + + /*while (!Serial) { + delay(10); + }*/ + Serial.println("eInk Calendar & Clock with CH32V203"); + SPI.begin(); + Serial.println("SPI started"); + pinMode(EPD_CS, OUTPUT); + digitalWrite(EPD_CS, HIGH); + + Wire.begin(); + Serial.println("Wire started"); + Serial.println("starting display, might take a bit.."); + display.begin(THINKINK_MONO); + Serial.println("display started"); + + while (! rtc.begin()) { + Serial.println("Couldn't find RTC"); + delay(10); + } +} + +void loop() { + Serial.println("we did it!"); + DateTime now = rtc.now(); + Serial.println("read rtc"); + char timeChar[6]; + sprintf(timeChar, "%02d:%02d", now.hour(), now.minute()); + String timeStr = String(timeChar); + String monthStr = monthsOfYear[now.month()]; + String dateStr = String(now.day()); + String yearStr = String(now.year()); + String dayOfWeekStr = daysOfTheWeek[now.dayOfTheWeek()]; + Serial.println(timeStr); + int16_t x1, y1; + uint16_t w, h; + if (lastTimeStr != timeStr) { + display.clearBuffer(); + display.fillRect(0, 0, 200, 60, EPD_BLACK); + display.drawRect(0, 0, 200, 170, EPD_BLACK); + display.setTextColor(EPD_WHITE); + display.setFont(&FreeSans24pt7b); + display.getTextBounds(dayOfWeekStr.c_str(), 0, 0, &x1, &y1, &w, &h); + display.setCursor((200 - w) / 2, (60 - h) / 2 + h); + display.println(dayOfWeekStr); + display.setTextColor(EPD_BLACK); + display.getTextBounds(dateStr.c_str(), 0, 0, &x1, &y1, &w, &h); + display.setCursor((200 - w) / 2, (170 - h) / 2 + h + 28); + display.println(dateStr); + display.setFont(&FreeSans18pt7b); + display.getTextBounds(monthStr.c_str(), 0, 0, &x1, &y1, &w, &h); + display.setCursor((200 - w) / 2, (60 + h) + 3); + display.println(monthStr); + display.getTextBounds(yearStr.c_str(), 0, 0, &x1, &y1, &w, &h); + display.setCursor((200 - w) / 2, (170 - h) - 5 + h); + display.println(yearStr); + display.setFont(&FreeSans12pt7b); + display.getTextBounds(timeStr.c_str(), 0, 0, &x1, &y1, &w, &h); + display.setCursor((200 - w) / 2, (200 - h) - 5 + h); + display.println(timeStr); + display.display(); + lastTimeStr = timeStr; + } + delay(30000); +}