Skip to content

Circuitpython Class to display an analog clock on multiple displays

License

Notifications You must be signed in to change notification settings

colonwq/kds_analogclock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Circuitpython Class to display an analog clock on multiple displays

Introduction

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.

Supported Boards

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)

Notes

  1. Lots of colors
  2. Black and White
  3. Uses Adafuit portal class for board
  4. Uses CircuitPython 8.2.10
  5. No portal class but cribbed local time code from the PortalBase class.
  6. Added the 128x32 OLED Feather Wing
  7. Added the TFT Gizmo for the display
  8. Ran out of memory early in the development attempt
  9. Added the 64x32 RGB LED Matrix
  10. Added PFC8523 RTC
  11. Should support all qualia displays but developed with the 2.1"

CP 9+ Notes

  • Apparently the /sd directory needs to be created on newly formatted boards.

Design Notes

Separation of class duties

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

Pre-computed the sin() and cos() values

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.

Reuse static image elements

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.

Update time

The base class will call the connectNetwork() after 12 hours of run time has passed.

Dynamic sizing on startup

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.

Utilities

  • 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.

Possible future / Todos

  • 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

About

Circuitpython Class to display an analog clock on multiple displays

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages