The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

170 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


5 Figure 7-15: Use the sense.clear function to turn off all the LEDs

To create your own version of the LED matrix pictured earlier in this chapter, with two
specifically selected LEDs lit up in red and blue, add the following lines to your program after
sense.clear() :

sense.set_pixel( 0 , 2 , ( 0 , 0 , 255 ))
sense.set_pixel( 7 , 4 , ( 255 , 0 , 0 ))

The first pair of numbers are the pixel’s location on the matrix, X (across) axis followed by
Y (down) axis. The second, in their own set of brackets, are the RGB values for pixel’s colour.
Click the Run button and you’ll see the effect: two LEDs on your Sense HAT will light up, just
like in Figure 7-10 on page 164.
Delete those two lines, and type in the following:

sense.set_pixel( 2 , 2 , ( 0 , 0 , 255 ))
sense.set_pixel( 4 , 2 , ( 0 , 0 , 255 ))
sense.set_pixel( 3 , 4 , ( 100 , 0 , 0 ))
sense.set_pixel( 1 , 5 , ( 255 , 0 , 0 ))
sense.set_pixel( 2 , 6 , ( 255 , 0 , 0 ))
sense.set_pixel( 3 , 6 , ( 255 , 0 , 0 ))
sense.set_pixel( 4 , 6 , ( 255 , 0 , 0 ))
sense.set_pixel( 5 , 5 , ( 255 , 0 , 0 ))
Free download pdf