ChickBot Arduino dance & sing

So, let’s put it all together so we can get our ChickBot moving & grooving at your command.

This is the starter program that your ChickBot came programmed as and it adds in some little extras to make it super simple for you to say how far it should move or turn. And we give you all the notes we know about so you can get any tune you like playing!

As the program is a bit longer than the others and has more detailed parts to it, it’s best to download it from here and we can concentrate on how you can make changes.

It will only take a second or so to download. On Windows you will need to right-click the file and Extract All to unzip it. Mac does this automagically.

Open up the program in the Arduino software (either from the Open command on the File menu, or double click the ChickBot_starter_v1.1.ino file). Now take a look at the loop section and you’ll see how we’ve made it almost like English to command your ChickBot. The commands you can use are picked out below in orange.

We start out with a SoundAndLEDAlert command that plays a tone and flashes the on-board LED.

We’ve got a WaitForButtonPress command that, well, as you’d expect, waits for the button to be pressed.

As we have set some calculations and definitions in the top section, we can tell ChickBot how far to move in the units of your choice, mm, cm or inches.

This gives us a super useful command of GoForward() – inside the brackets we tell the command how many steps to go, and by using cm or mm or inches, we can say how far to go. Here’s some examples:

GoForward( 10 * cm ) = move forward 10 cm

GoForward( 5 * mm ) = move forward 5 mm

GoForward( 3 * inches ) = move forward 3 inches

I bet you can guess what the backwards command is??? Yup, it’s GoBackwards() with exactly the same options.

Want your ChickBot to stop? That’s what the AllStop() command does. I don’t want to use the word Stop as ‘stop’ is a part of the programming language and if someone forgets the upper case S, the program won’t work as expected.

We have two ways of turning:

The simplest one is the HardTurn() with whether you want it to go Left or Right and how many steps. A hard turn is a turn that’s on the spot – one wheel goes forward and one wheel goes backwards, so ChickBot pivots around its front axle.

The second moves in an arc and is called SoftTurn(), again, you say if you want it to turn Right or Left and how many steps. A soft turn keeps one wheel stopped and the other wheel drives forward. This means it is a bigger turn than a hard turn, something to remember when planning your movements.

The program calculates the number of steps that are needed for various turn sizes, so you have some pre-prepared values of hardTurn360, hardTurn90, softTurn360 and softTurn90. The number in the name refers to the number of degrees of turn. As they are numbers, you can use maths to get different values – so if you want to turn around, a 180° turn, you could use hardTurn360 / 2 or hardTurn90 + hardTurn90. Using softTurn values with the hardTurn() command and vice versa won’t do any harm but won’t make any sense as the calculations can’t be mixed together.

Last but not least, we have an improved tune command so that you can setup as many tunes as you like and play which ever one you want. The tune (or music) definition is the same but with the option of calling it something more memorable:

Warning!There is no harm in trying stuff out. Using these commands can’t do any damage to your ChickBot unless you drive it off the edge of a table and it falls on the floor. So this isn’t much of a warning really, I just wanted to get your attention.

So, make changes, one at a time, to the loop section and see how you can get your ChickBot moving and singing to your command.