

The degrees selected should be the same as the condition for vertical, so that there’s no overlap or gap in the code. The second condition applies when the tilt sensor is more than 20 degrees to the left. We found that 20 degrees either side was good, but you may prefer something different. If the range is too small, you’ll find it hard to hold the steering wheel close enough to vertical, and the racing car will veer off to the side when you don’t want it to. Very important for this part of the code is to nominate a suitable range either side of vertical. Under those conditions, costume 1 will show, which is when the car is facing straight ahead. The first part of this code applies when the tilt sensor is close to vertical – less than 20 degrees either left or right.

All three are inside a forever loop, so the sprite will constantly check which condition is applicable. That’s one condition for each costume, so that the sprite knows what to do. Notice that there are three ‘if’ conditions in this section of code. At the same time, we want the car to move left or right when we turn the steering wheel, so the blue lines of code tell the car to move along the horizontal axis.įinal part of the code for the racing car, using Lego Wedo tilt sensor blocks It’s controlled by the tilt angle of the sensor, either left, right, or vertical. The first is to control which costume is used for the racing car sprite.

In this code, the tilt sensor is used to instruct two different actions simultaneously.

The sensor can detect up/down and left/right movement, which it feeds to the smarthub. The steering wheel was the first project that required the sensor, so there was a lot of learning. Liam has been working on some other Wedo projects recently, but they’ve been using only the motor and the smarthub. The tilt sensor is one of the key components in the Lego Wedo 2.0 kit, along with a motion sensor, motor and smarthub. Lego Wedo tilt sensor attached to the back of the steering wheel It’s taken a while, but it’s definitely worth getting the rest of the code up and running. In the final section of code, the Lego Wedo tilt sensor finally comes into the game. Racing car code part 3 – when the car crashes Part 4 – using the tilt sensor on the steering wheel
