Skip to content

Commit 60d26f9

Browse files
committed
code for ch32v203 eink calendar clock
Arduino code for the CH32V203 QT Py eInk calendar clock
1 parent 2ab0856 commit 60d26f9

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed

CH32V203_eInk_Calendar_Clock/.none.test.only

Whitespace-only changes.
62.3 KB
Binary file not shown.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Arduino.h>
6+
#include <SPI.h>
7+
#include "Adafruit_TinyUSB.h"
8+
#include "Adafruit_ThinkInk.h"
9+
#include "RTClib.h"
10+
#include <Wire.h>
11+
#include <Fonts/FreeSans24pt7b.h>
12+
#include <Fonts/FreeSans18pt7b.h>
13+
#include <Fonts/FreeSans12pt7b.h>
14+
15+
#define EPD_DC PA3
16+
#define EPD_CS PA2
17+
#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay)
18+
#define SRAM_CS PA1
19+
#define EPD_RESET -1 // can set to -1 and share with microcontroller Reset!
20+
#define EPD_SPI &SPI // primary SPI
21+
22+
// 1.54" Monochrome displays with 200x200 pixels and SSD1681 chipset
23+
ThinkInk_154_Mono_D67 display(EPD_DC, EPD_RESET, EPD_CS, SRAM_CS, EPD_BUSY, EPD_SPI);
24+
25+
RTC_DS3231 rtc;
26+
27+
char daysOfTheWeek[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
28+
char monthsOfYear[13][4] = {"NULL", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
29+
30+
bool start = true;
31+
32+
String lastTimeStr = "00:00";
33+
34+
void setup() {
35+
Serial.begin(115200);
36+
37+
/*while (!Serial) {
38+
delay(10);
39+
}*/
40+
Serial.println("eInk Calendar & Clock with CH32V203");
41+
SPI.begin();
42+
Serial.println("SPI started");
43+
pinMode(EPD_CS, OUTPUT);
44+
digitalWrite(EPD_CS, HIGH);
45+
46+
Wire.begin();
47+
Serial.println("Wire started");
48+
Serial.println("starting display, might take a bit..");
49+
display.begin(THINKINK_MONO);
50+
Serial.println("display started");
51+
52+
while (! rtc.begin()) {
53+
Serial.println("Couldn't find RTC");
54+
delay(10);
55+
}
56+
}
57+
58+
void loop() {
59+
Serial.println("we did it!");
60+
DateTime now = rtc.now();
61+
Serial.println("read rtc");
62+
char timeChar[6];
63+
sprintf(timeChar, "%02d:%02d", now.hour(), now.minute());
64+
String timeStr = String(timeChar);
65+
String monthStr = monthsOfYear[now.month()];
66+
String dateStr = String(now.day());
67+
String yearStr = String(now.year());
68+
String dayOfWeekStr = daysOfTheWeek[now.dayOfTheWeek()];
69+
Serial.println(timeStr);
70+
int16_t x1, y1;
71+
uint16_t w, h;
72+
if (lastTimeStr != timeStr) {
73+
display.clearBuffer();
74+
display.fillRect(0, 0, 200, 60, EPD_BLACK);
75+
display.drawRect(0, 0, 200, 170, EPD_BLACK);
76+
display.setTextColor(EPD_WHITE);
77+
display.setFont(&FreeSans24pt7b);
78+
display.getTextBounds(dayOfWeekStr.c_str(), 0, 0, &x1, &y1, &w, &h);
79+
display.setCursor((200 - w) / 2, (60 - h) / 2 + h);
80+
display.println(dayOfWeekStr);
81+
display.setTextColor(EPD_BLACK);
82+
display.getTextBounds(dateStr.c_str(), 0, 0, &x1, &y1, &w, &h);
83+
display.setCursor((200 - w) / 2, (170 - h) / 2 + h + 28);
84+
display.println(dateStr);
85+
display.setFont(&FreeSans18pt7b);
86+
display.getTextBounds(monthStr.c_str(), 0, 0, &x1, &y1, &w, &h);
87+
display.setCursor((200 - w) / 2, (60 + h) + 3);
88+
display.println(monthStr);
89+
display.getTextBounds(yearStr.c_str(), 0, 0, &x1, &y1, &w, &h);
90+
display.setCursor((200 - w) / 2, (170 - h) - 5 + h);
91+
display.println(yearStr);
92+
display.setFont(&FreeSans12pt7b);
93+
display.getTextBounds(timeStr.c_str(), 0, 0, &x1, &y1, &w, &h);
94+
display.setCursor((200 - w) / 2, (200 - h) - 5 + h);
95+
display.println(timeStr);
96+
display.display();
97+
lastTimeStr = timeStr;
98+
}
99+
delay(30000);
100+
}

0 commit comments

Comments
 (0)