I watched a video from Dave's Garage where he wrote an analog clock for his LED display. Afterwards I realized I had a few Adafruit CircuitPython powered microcontrollers with displays. I have since implemented a CircuitPython class to display an analog clock.
I have adopted my class to the boards around my desk as I find them. Most of these came from Adaboxes or other small projects I started and eventually abandoned.
| Board | Supported | Notes |
|---|---|---|
| Funhouse | Yes | (1)(3) |
| Magtag | Yes | (2)(3) |
| Pyportal | Yes | (1)(3) |
| M4 Matrix | Yes | (1)(3)(4)(9) |
| Feather Huzzah32 | Yes | (2)(4)(5)(6) |
| MacroPad | Yes | (2)(4)(10) |
| Circuit Playground Express | No | (7)(8) |
| CLUE | Yes | (2)(4)(10) |
| Qualia S3 | Yes | (1)(3)(11) |
- Lots of colors
- Black and White
- Uses Adafuit portal class for board
- Uses CircuitPython 8.2.10
- No portal class but cribbed local time code from the PortalBase class.
- Added the 128x32 OLED Feather Wing
- Added the TFT Gizmo for the display
- Ran out of memory early in the development attempt
- Added the 64x32 RGB LED Matrix
- Added PFC8523 RTC
- Should support all qualia displays but developed with the 2.1"
- Apparently the /sd directory needs to be created on newly formatted boards.
The kds_analog clock base class is responsible for the pre-computation of needed math values and calculation and display of the clock elements.
The displays which use the kds_analog clock are responsible for doing the following
- init
- Call the super class init
- Declare the color values used
- Create the portal object
- Create the display object
- Set any display update parameters
- Call the following functions, pre_calc, drawStatic, drawClock and connectNetwork
- connectNetwork
- Necessary code to connect to the internet or configure RTC usage
- Necessary code to update system time
There are 60 possible locations for the clock hands. The code pre-computes the sin() and cos() values for these angles and stores them in a table for a quick lookup.
The entire display is not generated with each update. The following elements are always static:
- The outer clock circle
- The center clock circle
- The tick marks around the clock
- The background behind the clock (if used)
The hands are regenerated when they move from a previous location. The hour hand updates only when it aligns with a tick mark.
The base class will call the connectNetwork() after 12 hours of run time has passed.
The size of the various elements is calculated based on the side of the display. The radius of the clock face is the smaller dimension of the display dimensions. All other elements are based from the radius with the values pre-calculated on startup.
- examples/macropad_rp2040/RTC-pcf8523/code.py is an example code.py to program an RTC. This was written to use the Adafruit Micropad display wrapper class. The actual RTC code is small but portable.
- Add more boards and displays
- Auto discover display size for boards with multiple display options.
- Memory optimization. I think I can cut the sin()/cos() table by a quarter
- Clean up the connectNetwork(). The portal classes for the various boards are almost the same.
- Bug fixes. I think I have a 12:00 display issue with the hour hand.
- Write a huzzah portal??
- Pictures