Make HaloCode the Steering Wheel of the Car on Stage
When you tilt HaloCode to the left, the car on stage will move leftward. When you tilt HaloCode to the right, the car will move rightward. HaloCode is just like the steering wheel of the car.
Use the motion sensor
The motion sensor of HaloCode detects how HaloCode moves. We'll use the motion sensor in this example. When HaloCode is tilted to the left, a corresponding piece of message will be sent to the car on Scratch Stage to make it move leftward. Likewise, when HaloCode is tilted to the right, a corresponding piece of message will tell the car to move rightward.
1. Drag a Control blockto the Scripts area. Add a Sensing block to the condition.
2. Likewise, for the right side, duplicate the script, and select "right-tilted".
3. Add two Events blocks. Create two pieces of message, namely "left" and "right".
4. Add an Events blockand a Control block .
Add a sprite
5. Under "Sprites", click "+". In the Sprites Library, choose "Car" from the Transportation category.
6. Delete the default sprite "Panda".
Program the car
7. Add three Motion block:, , .
8. Add an Events block, and choose message "left". When the car receives message "left", it will move leftward for 10 steps.
10. Likewise, for the rightward part, duplicate the script. Choose message "right", and change the direction to "90".
Note: the message received should be the same message that is broadcast.
11. Press the button of HaloCode and then tilt it!