Sense Hat Comes Alive

Remember the Raspberry Pi Sense Hat? Originally designed 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 do with an 8×8 screen? You might be surprised 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 array to represent the screen, which isn’t a big deal since 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 move 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. Looking 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 more than just light up LEDs as you can see from this weather dashboard.


Filed under: Raspberry Pi

from Hackaday http://ift.tt/2qpa4os
via IFTTT