The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

186 THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE


These mappings mean you can use the same kind of Events blocks as you would for
reading from the keyboard. Drag a when space key pressed block onto your script area, then
use the arrow to change it into a when up arrow key pressed block. To give it something to
do, drag a say Hello! for 2 secs block under it.

when clicked
set allpixelsto off

when up arrow keypressed
say Hello!for^2 secs

Push the joystick upwards and you’ll see the Scratch cat say a cheery “Hello!”
Next, edit the say Hello! for 2 secs block into a say Joystick Up! for 2 secs block, and
continue to add Events and Looks blocks until you have something for each of the five ways
the joystick can be pressed.

when^ clicked
setallpixelsto off

when up arrow keypressed
say Joystick Up! for^2 secs

when down arrow keypressed
say Joystick Down! for^2 secs

when left arrow keypressed
say Joystick Left! for^2 secs

when right arrow keypressed
say Joystick Right! for 2 secs

when enter keypressed
say Joystick Pushed! for^2 secs
Free download pdf