Chapter 7 Physical Computing with the Sense HAT 181
THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE
Inertial sensing in Scratch
Start a new program in Scratch and load the Sense HAT extensions. Start your program in
the same way as before: drag a when clicked Events block onto your script area, then
drag a set all pixels to white block underneath it and use the down arrow to change it into a
set all pixels to off block.
Next, drag a forever block to the bottom of your existing blocks and fill it with a say Hello!
block. To show a reading for each of the three axes of the IMU – pitch, roll, and yaw – you’ll
need to add join blocks plus the corresponding Sense HAT blocks. Remember to include
spaces and commas, so that the output is easy to read.
when clicked
setallpixelsto off
forever
say join Pitch: join pitch join , Roll: join roll join , Yaw: yaw
Click the green flag to run your program, and try moving the Sense HAT and Raspberry Pi
around – being careful not to dislodge any cables! As you tilt the Sense HAT through its three
axes, you’ll see the pitch, roll, and yaw values change accordingly (Figure 7-26).
5 Figure 7-26: Displaying the pitch, roll, and yaw values