149
C H A P T E R 1 0
A N I N T R O D U C T I O N T O S C R A T C H
Although this example is effective for introducing some important programming concepts,
it's hardly the best way the game could be coded . Scratch includes a message broadcast system
that allows code attached to one object to communicate with code attached to another,
which enables you to create much neater collision results that don't rely on carefully-timed
pauses in order to make sense .
To experiment with broadcasting, try using the
and
blocks
broadcast
when I receive
from the Control palette . A message created for a broadcast block in any object can trigger
code in any other object using the
flag, meaning you can use it to link
when I receive
multiple objects and their code together .
Robotics and Sensors
In addition to purely software-based inputs and outputs, it's also possible to tie Scratch into
external hardware using sensor boards and robotics systems . Thanks to its multithreaded
nature and powerful inter-process messaging system, Scratch can be used to create a surpris-
ingly advanced robotics engine and is by far the easiest way to place a Raspberry Pi at the
heart of a simple robot .
Unlike Python, which is a more powerful but significantly more complex programming lan-
guage, Scratch can't make use of the Raspberry Pi's GPIO port to communicate with external
hardware . As a result, it needs some additional equipment before it can interact with the
physical world .
Sensing with the PicoBoard
Designed by the SparkFun electronics company, the PicoBoard is an add-on module that
connects to a computer running Scratch and provides a variable slider input, a light sensor, a
button, a sound sensor and four pairs of alligator clips that can be used to monitor external
electrical devices .
There are currently two types of PicoBoard: the original model, which uses a serial connec-
tion, and its replacement, which uses a USB connection . The latter is supported by the
Raspberry Pi . Simply connect it to a free USB port or a port on a USB hub connected to the
Pi, restart Scratch, and you'll be able to use its various functions within the Scratch interface .
Details on the PicoBoard can be found at
http://www.sparkfun.com/products/
.
10311
Need help?
Do you have a question about the Raspberry Pi and is the answer not in the manual?
Questions and answers