The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1

(^74) THE OFFICIAL RASPBERRY PI BEGINNER'S GUIDE
You can extend this project further by having it calculate roughly how far the International
Space Station has travelled in the time it took you to press the SPACE key, based on the
station’s published speed of seven kilometres per second. First, create a new variable called
‘distance’. Notice how the blocks in the Data category automatically change to show the new
variable, but the existing time variable blocks in your program remain the same.
Add a set distance to 0 block, then drag a ● ● Operators block – indicating
multiplication – over the ‘0’. Drag a time reporting block over the first blank space, then type
in the number ‘7’ into the second space. When you’re finished, your combined block reads
set distance to time
7. This will take the time it took you to press the SPACE key and
multiply it by seven, to get the distance in kilometres the ISS has travelled.
when clicked
say Hello! British ESA Astronaut Tim Peake here. Are you ready? for^2 secs
wait^1 secs
say Hit Space!
reset timer
wait until key space pressed?
say join Your reaction time was join timer seconds.
set time to timer
set distance to time *^7
Add a wait 1 secs block and change it ‘4 secs’. Finally, drag another say Hello! block onto
the end of your sequence and add two join blocks, just as you did before. In the first white
space, type ‘In that time the ISS travels around ’, remembering to include the space at the end,
and in the last white space type ‘ kilometres.’, again remembering the space at the start.

Free download pdf