Users Manual
CLASS 2
138
Button sensor and the servo motor
Now, code for the alligator’s mouth movement when the button sensor is pressed.
First, we are going to make the sound sensor produce a short sound whenever the button sensor is pressed. And
when the button sensor is pressed, the alligator’s mouth will open until it reaches the angle that was set by the
volume sensor. Make the script below!
For right now, the button sensor is connected to digital port 3, which is the right end port among all input ports.
Make the sound sensor to play its effect sound for 0.1 sec whenever the button sensor is pressed. And, make the
alligator open its mouth until it reaches the angle set by the volume sensor when the button sensor is pressed.
The last block ‘wait until…’ will be introduced later in the next level. It’s simply a block that orders the alligator to
wait until the volume sensor is not pressed. There is a block that keeps the sound playing and the mouth open
when the button sensor is pressed. Though, if we put ‘is the sensor digital 3 pressed? NOT’ condition, the mouth
will open once and the sound play once until the button sensor is unpressed. Let’s learn more about the ‘wait’
block in level 4.
You just completed coding the alligator robot!
Combine all the scripts you have made into one script.
Experiencing
the alligator robot coding