Make HaloCode the Steering Wheel of the Car on Stage

Programming Result

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 block if () then () to the Scripts area. Add a Sensing block HaloCode is ()? to the condition.

2. Likewise, for the right side, duplicate the script, and select "right-tilted".

Message broadcast

3. Add two Events blocks broadcast (). Create two pieces of message, namely "left" and "right".

4. Add an Events block when button is pressed and a Control block forever.

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: set rotation style (left-right), point in direction (-90), move (10) steps.

8. Add an Events block when I receive (), 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!

Last updated