ChickBot micro:bit dance & sing

Let’s bring this all together, get the ChickBot moving in sequences, displaying messages and playing tunes.

We have a master script that we use to make it simpler to control the motor control pins. You can make a copy into your editor by clicking here.

If you zoom out or click the target icon bottom right you’ll see the whole script. This master script has a setup block in the top left and a large forever control loop on the right. The part that interests us is this part:

Click to enlarge

Click to enlarge

This demonstrates the minimum script you could have – set the Motors to GoForward, allow that to run for one second by pausing the script before setting the Motors to Stop.

To add more movements, you need to duplicate the ‘set Motors’ block and the pause block that allows that action to run. You can have as many as you’d like. As well as GoForward and GoBackward, there are two sorts of turn.

A standard turn, which we call a hard turn here at ChickBot HQ, is a turn on the spot around the centre between the two wheels. There is a pre-calculated variable¬†that, with fresh alkaline batteries, should provide a 90 turn, called pause4Turn90.¬†A soft turn is a turn where one motor is turned off, so it turns around that wheel. There is a corresponding pause4SoftTurn90. If you are using rechargeable batteries which don’t give out as much voltage as disposable cells or the batteries are running low, you’ll have to increase the values for the turns – some experimentation & calibration will be required.

There is a small block setup to turn off the motors if you press button B.

You can build up a multi-step sequence. Here is a much longer control script as an example.

Click to enlarge

Click to enlarge

For the curious, the forever loop is constantly checking the value of the Motors variable and setting the outputs pins as required. This saves on having to set the four motor control pins for each and every movement.