- Raspberry Pi with Sense HAT
The participant starts by running a pre-written script which scrolls the message "Hello world". They then change the message to one of their own, and run again. They can then change the colour. Finally they are given code with a loop showing the Raspberry Pi logo followed by the scrolling message at a different speed and in different colours, which they can play with.
from sense_hat import SenseHat
sense = SenseHat()
sense.show_message("Hello world")
- Run the code to see what it does
- Change the message from "Hello world" to something else, and re-run the code
from sense_hat import SenseHat
O = (0, 0, 0)
R = (255, 0, 0)
G = (0, 255, 0)
B = (0, 0, 255)
C = (0, 255, 255)
M = (255, 0, 255)
Y = (255, 255, 255)
W = (255, 255, 255)
sense = SenseHat()
sense.show_message("Hello world", text_colour=M, back_colour=O)
- Observe the colour values. These are RGB (red-green-blue) values making up pixel colours. Run the code to see the message scroll in magenta (made up of red and blue).
- Choose from the listed colours and change the text colour and back colour. Re-run the code to see your colours.
- Play with different colour combinations to see what works well.
from sense_hat import SenseHat
from time import sleep
sense = SenseHat()
O = (0, 0, 0)
R = (128, 0, 0)
G = (0, 128, 0)
B = (0, 0, 128)
C = (0, 128, 128)
M = (128, 0, 128)
Y = (128, 128, 128)
W = (128, 128, 128)
logo = [
O, G, G, O, O, G, G, O,
O, O, G, G, G, G, O, O,
O, O, R, R, R, R, O, O,
O, R, R, R, R, R, R, O,
R, R, R, R, R, R, R, R,
R, R, R, R, R, R, R, R,
O, R, R, R, R, R, R, O,
O, O, R, R, R, R, O, O,
]
while True:
sense.set_pixels(logo)
sleep(2)
sense.show_message("Hello world", scroll_speed=0.05, text_colour=G, back_colour=R)
- An 8x8 pixel art image has been created using red and green pixels. Run the code to see what the image makes.
- You'll notice that the code loops around, showing the image for 2 seconds and then scrolling the message faster than it did before. Try changing the scroll speed and the sleep time.
- Try changing the colours in the picture, or even try to make your own picture!
To reset the activity, simply copy back the three Python files from a saved location. Ideally also run cat /dev/zero > /dev/fb1
to clear the Sense HAT display.