59
LEGO® WeDo (V)
Programming in Scratch*
By Edwar Romero
Cover image by Osvaldo Romero
We continue here with our plan to dominate the world! One
LEGO® brick at a time. The best part is that we can start
doing it with programmable WeDo™ bricks the best we can.
We continue here our programming quest in Scratch as the
software for our battles. In previous issues of this magazine,
we have covered the WeDo software basics and the equivalent
commands used in the open platform Scratch.
We have talked before about how to program a few basic
things, like the fundamentals for the motor and the different
alternatives to turn it on and off. Last time we started talking
about different options for programming the Amazing
Mechanisms included with the WeDo software: Dancing Birds,
the Smart Spinner and the Drumming Monkey, and how to do
it using Scratch. This time we continue with the next set of 3
mechanisms: the Hungry Alligator, the Roaring Lion and the
Flapping Bird (designs 4, 5 and 6 from the gure below).
60
Let’s start with the Hungry Alligator. The WeDo software
program begins when hitting the letter “A” on the keyboard
to turn the motor one way to open the powerful jaws of
this alligator. After that, it will make a scary bite sound and
immediately turn the motor the other way to close the jaws
and bite everything that gets close enough. It will chomp for a
few seconds before the next bite. The next image shows this
sequence programmed in WeDo.
You can program it in Scratch in a similar fashion. You need to
look for the Control tab to nd the “when __ key pressed” and
selected a letter on the drop down menu. The letter “a” was
selected for this example.
You can select the space bar since you don’t have to look at
the keyboard constantly to nd it. You need to use the “motor
direction” to open the alligator jaws, after that the option “motor
on for” 1 second under the Motion menu. Next, you need to
select the option “play sound”. By default the meow sound
appears, you may want to change it since it doesn’t sound
ferocious enough for a hungry alligator. So, you need to import
a new sound for this task. You need to go to the zone where
you are programming, look for the Sounds tab, hit the Import
button, and look around for a suitable sound. I used the one
called Slurp in the Human folder. You may choose a different
one, download it from the Internet or even record your own
version. Don’t forget to choose the sound from the drop down
menu, otherwise your alligator will sound like a kitten. Once
done, you need to select the motor direction in the opposite
way to see the jaws closing for chomping down whatever the
fangs caught.
We can start thinking about having our own robotic security
system using LEGO® bricks. What if you have a wolf or huge
bear as a guardian for your home, built completely with LEGO
and programmed to behave as you like? It seems like world
domination is one step closer!
Next is the Roaring Lion design. The programming in WeDo is
as shown below. One key is used to get it up and roaring and
another to send it to sleep. When the big cat is up and roaring
like a erce beast, you need to congure the power level of the
motor and check the motor is turning the right way. Don’t forget
to add a ferocious sound for this feline.
When our big cat is tired of roaring, it needs to go for a good
night’s sleep. For that, you need to program the motor power
and check if the motor is turning in the right direction for the
lion to go to rest. You also need to nd a sleepy sound to show
this cat is quite friendly when it is tired, so we can get close
without getting into trouble.
61
Performing the programming in Scratch shouldn’t be difcult
for this task after all we have learned with the previous design.
You need to verify and test several motor power levels for the
lion to behave like the king of the jungle it is. We don’t want
our robotic friend to fall apart while performing, do we? The
most difcult part for the Roaring Lion programming is nding
a hungry lion sound. You can try your best impersonation to
record this sound. You can be the voice of your own creation!
You can also resort to a sound le of your liking from the
Internet if the ones in Scratch are not erce enough.
For going to sleep, our feline friend can be programmed in
Scratch as shown below. You need to be really creative when
choosing a sleeping sound. You can try between the ones
available in the Scratch folder to see if there is something you
like or you can try to record the best impersonation you can for
this sleepy cat.
In order to complete the three designs from the Wild Animals
set, we still need to work with the Flapping Bird. The Flapping
Bird is a lot less complicated than previous designs. It only
uses the tilt sensor to activate the wing apping sound.
The basic WeDo program should look like the image below.
We have a loop that allows the cycle to repeat as many times
as needed. There is also the wait command connected with
the tilt sensor. The tilt sensor is on the horizontal position (no
tilt), so when is moved to another position it will activate the
wind apping sound for this huge bird. You can imagine this
bird moving its powerful wings through the air. Is quite terroric,
isn’t it?
Working in Scratch, the program should look similar to the
one found below. The “forever if” loop can be found under the
Control menu. If you look under the Operators menu, you’ll nd
the equal to block “_=_”. You can play with the value to nd
other interesting congurations. Going through the Sensing
menu, close to the end you’ll nd the “sensor value” block. On
that drop down menu, you will discover the tilt sensor like the
one on the image.
Finding the right sound for the apping of the wings for our big
bird is a complete challenge for this creation too. You can try
and record the sound effects for this design as well. You can
also search on the Internet for the sound of your preference.
That’s all for now folks, stay tuned for the advanced
programming of these creations in the next issues of
HispaBrick Magazine®.
You can nd more information, and building and programming
instructions for the designs presented here and many more at:
www.wedobots.com
www.facebook.com/wedorobots
* This tutorial uses Scratch version 1.4 - The use of LEGO®
WeDo in Scratch 2.0 is still experimental.
#