Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active November 11, 2018 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennuttall/66c18f016d1137b3c3c5960863e2ac72 to your computer and use it in GitHub Desktop.
Save bennuttall/66c18f016d1137b3c3c5960863e2ac72 to your computer and use it in GitHub Desktop.

Sense HAT scroll message

What's needed

  • Raspberry Pi with Sense HAT

The activity

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.

Tab 1

from sense_hat import SenseHat

sense = SenseHat()

sense.show_message("Hello world")
  1. Run the code to see what it does
  2. Change the message from "Hello world" to something else, and re-run the code

Tab 2

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)
  1. 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).
  2. Choose from the listed colours and change the text colour and back colour. Re-run the code to see your colours.
  3. Play with different colour combinations to see what works well.

Tab 3

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)
  1. An 8x8 pixel art image has been created using red and green pixels. Run the code to see what the image makes.
  2. 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.
  3. Try changing the colours in the picture, or even try to make your own picture!

Reset

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment