The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

164 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


5 Figure 7-10: LED matrix coordinates system

There are eight LEDs in each row of the display, and eight in each column (Figure 7-10).
When counting the LEDs, though, you – like most programming languages – should start at
0 and end at 7. The first LED is in the top-left corner, the last is in the bottom right. Using the
numbers from the rows and columns, you can find the coordinates of any LED on the matrix.
The blue LED in the pictured matrix is at coordinates 0, 2; the red LED is at coordinates 7, 4.
The X axis, across the matrix, comes first, followed by the Y axis, down the matrix.
When planning pictures to draw on the Sense HAT, it may help to draw them by hand first, on
gridded paper, or you can plan things out in a spreadsheet such as LibreOffice Calc.

Pictures in Scratch
Start a new project in Scratch, saving your existing project if you want to keep it, and load the
Sense HAT extension from the More Blocks category. You’ll need to do this each time you
create a new Scratch Sense HAT program, or you won’t have access to the blocks you need.
Drag a when clicked Events block onto the script area, then drag a set all pixels to white
block underneath it.

X
0 1 2 3 4 5 6 7

Y 0


1 2 3 4 5 6 7

Free download pdf