The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

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

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


Click the green flag, and you’ll see your LEDs light up to match the matrix image
(Figure 7-10) on page 164. Congratulations: you can control individual LEDs!
Edit your existing set pixel blocks as follows, and drag more onto the bottom until you have
the following program:


when clicked


set allpixels to R^0 G^0 B^0


set pixel^2 ,^2 to blue


set pixel^4 ,^2 to blue


set pixel^3 ,^4 to blue


set pixel^1 ,^5 to blue


set pixel^2 ,^6 to blue


set pixel^3 ,^6 to blue


set pixel^4 ,^6 to blue


set pixel^5 ,^5 to blue


Before you click the green flag, see if you can guess what picture is going to appear based
on the LED matrix coordinates you’ve used, then run your program and see if you’re right!
While you can use the set pixel blocks to draw simple images, the current version of the
Scratch 2 Sense HAT extension is not well suited to complex images or animations. For these,
consider switching your program to Python instead.


CHALLENGE: NEW DESIGNS
Can you design more pictures? Try getting some graph or
grid paper and using it to plan out your picture by hand first.
Can you draw a picture and have the colours change?
Free download pdf