Unicorn HatHD Clock - need help to port code from Sense Hat


Hi there,
I recently came across a great little project by Steve Amor to create a Pi clock using the Hours and Minutes displayed on 2 lines. It was originally written for the Sense Hat but as I’m the proud owner of a new Unicorn Hat HD I’m thinking about porting the code to work with the Unicorn HD.

I’m new to Python so I need some (a lot of) help!

Here’s the original code (used with permission):

From looking at the code, I see that the digits are created by using arrays. If I were to do the same thing with the Unicorn would I need to loop through the array and turn on each LED individually?

Many thanks in advance!



Looks like all the digits are 4x4, and are chopped out of the source array and pasted into the target before being coloured depending on their position.

There are so many ways to accomplish a similar effect! With Unicorn HAT HD you have whole 8x8 pixel segments to dedicate to each character, so you can use all that space, or use 5x7 with spacing, or just use a regular font as demonstrated (albeit with some complexity) in: https://github.com/pimoroni/unicorn-hat-hd/blob/master/examples/text.py

There’s no real need to maintain a separate buffer, like the code you’ve posted, you can just copy the relevant pixels right into Unicorn HAT HD’s buffer using set_pixel and the relevant offsets for each digit.

Step 1. is to come up with a font, if you’re going to approach it the same way as this example.