How to control the pixel matrix on your Sense Hat using the joystick - Raspberry Pi

Опубликовано: 29 Сентябрь 2024
на канале: MrMattperreault
5,151
39

This quick tutorial shows you how you can create a picture on the sense hat screen and then control it using the joystick. In this specific example we create a smiley face and then make it face, left or right depending on which direction we push the joystick.

#Below is the code from the video

from sense_hat import SenseHat

sense = SenseHat()

sense.clear()

r = (255,0,0)
g = (0, 255, 0)
b = (0, 0,255)

O = (0,0,0)
X = (255,255,255)

smileLeft = [
O,X,X,X,X,X,X,O,
X,O,O,O,O,O,O,X,
X,O,X,O,X,O,O,X,
X,O,O,O,O,O,O,X,
X,X,O,O,O,X,O,X,
X,O,X,X,X,O,O,X,
X,O,O,O,O,O,O,X,
O,X,X,X,X,X,X,O
]

smileRight = [
O,X,X,X,X,X,X,O,
X,O,O,O,O,O,O,X,
X,O,O,X,O,X,O,X,
X,O,O,O,O,O,O,X,
X,O,X,O,O,O,X,X,
X,O,O,X,X,X,O,X,
X,O,O,O,O,O,O,X,
O,X,X,X,X,X,X,O
]


def left():
sense.set_pixels(smileLeft)

def right():
sense.set_pixels(smileRight)

sense.stick.direction_left = left
sense.stick.direction_right = right

while True:
pass