SENSE HAT COMES alive

July 25, 2022 0 By bqk

remember the Raspberry Pi sense Hat? originally developed for a mission to the international space Station, the board has quite a few sensors onboard as well as an 8×8 RGB LED matrix. What can you finish with an 8×8 screen? You might be amazed if you use [Ethan’s] Python sense Hat animation library. You can get the full visual effect in the video below.

The code uses an range to represent the screen, which isn’t a big deal because there are only 64 elements. turning on a particular element to animate, say, a pong puck, isn’t hard with or without the library. Here’s some code to do it with the library:

for x in range(0,7):
ect.cell(image,[0,x],[randint(0,255), randint(0,255), randint(0,255)],0.1)
ect.cell(image,[0,x],e,0.1)
for x in range(7,0, -1):
ect.cell(image,[0,x],[randint(0,255), randint(0,255), randint(0,255)],0.1)
ect.cell(image,[0,x],e,0.1)
Each loop draws a box with a random color and then erases it before going to the next position. The second for loop makes the puck relocation in the opposite direction. You can probably deduce that the first argument is the screen array, the second is the position. The third argument sets the color, and the final argument sets an animation timer. taking a look at the code, though, it does look like the timer blocks which is probably not going to work for some applications.

If that’s all there was, this wouldn’t be worth too much, but you can also draw triangles, circles, and squares. For example:

ect.circle(image,(4,4), 3, [randint(0,255), randint(0,255), randint(0,255)], 0.1)
We covered the sense Hat awhile back. Of course, it does a lot much more than just light up LEDs as you can see from this weather dashboard.