The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1
Chapter 7 Physical Computing with the Sense HAT 169

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


The sense.clear() is designed to clear the LEDs of any previous programming, but
accepts RGB colour parameters – meaning you can change the display to any colour you like.
Try editing the line to:


sense.clear( 0 , 255 , 0 )

Click Run, and the Sense HAT will go bright green (Figure 7-14). Experiment with different
colours, or add the colour-name variables you created for your Hello World program to make
things easier to read.


5 Figure 7-14: The LED matrix lit up in bright green


To clear the LEDs, you need to use the RGB values for black: 0 red, 0 blue, and 0 green.
There’s an easier way, though. Edit the line of your program to read:


sense.clear()

The Sense HAT will go dark; for the sense.clear() function, having nothing between the
brackets is equivalent to telling it to turn all LEDS to black – i.e. switch them off (Figure 7-15,
overleaf). When you need to completely clear the LEDs in your programs, that’s the function
to use.

Free download pdf