The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

166 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


Click the green flag, and your program will run the same as before: all the LEDs will turn
bright white. This time, though, you can mix different colours yourself by choosing varying
amounts of red, green, and blue – labelled R, G, and B in the block respectively. Each can be
as little as zero and as much as 255. Try changing the block to set all pixels to R 0 G 255 B 0
and clicking the green flag; this time your Sense HAT will light up bright green (Figure 7-12).

5 Figure 7-12: Lighting all the pixels in bright green

Try experimenting with different colour values to find your favourites, and be sure to write
them down so you don’t forget them for future programs!
To make a picture, you need to be able to control individual pixels. To create your own
version of the LED matrix example pictured at the start of this section, with two specifically
selected LEDs lit up in red and blue, change your set all pixels to R 0 G 255 B 0 block to
set all pixels to R 0 G 0 B 0 then drag two set pixel 0, 0 to white blocks underneath it.
Finally, edit these blocks as follows:

when clicked


setallpixelstoR^0 G^0 B^0


setpixel^0 ,^2 to blue


setpixel^7 ,^4 to red

Free download pdf