My Cart:

0 item(s) - £0.00
You have no items in your shopping cart.

0

Guide For Coding Indicators On The :MOVE mini

A neat little trick we have been working on here at Kitronik HQ is to code a :MOVE mini to indicate when it is turning, a little nod to road safety. Once again we are controlling our :MOVE mini with radio signals, but this time we are using “flags” in the code for even better functionality.

Guide For Coding Indicators On The :MOVE mini

You may have noticed that some of the more recent cars utilise LEDs for their lights and indicators, some, in particular, have 'animated' indicators that roll the lights in the direction of the upcoming manoeuvre. That is the effect we were going for here. As always, you can grab the code at the foot of this resource.

 

What you will need:

 

Coding Indicators On The :MOVE mini:

indicator code :MOVE min for the microbit full code

This code is again split into three parts an on start, an on radio received and a forever loop. The on start is pretty simple just setting up the location of the ZIP LEDs on the :MOVE mini, the brightness and radio group. The more interesting blocks are the other two…

indicator code :MOVE min for the microbit radio

The on radio receive code interprets the instructions from another micro:bit, clears all the ZIP LEDs and creates flags with the true/false statements. Flags in coding are like signals. They indicate to the rest of the code that something is in a particular state, in this case that the :MOVE mini is turning.

When we are changing direction we change our flags. For example when we tell the MOVE: mini to turn left we set turn_left_indicator_on to true while leaving turn_right_indicator_on as false.  When we stop or begin driving forwards we set both statements to false. This ensures that our indicators will turn off and that at most only one of our indicators will be on at a time.

indicator code :MOVE min for the microbit

This final set of code uses the flags established in the radio receive to answer if statements. In this case the if statement asks is turn_left_indicator_on true? If it is then it switches on a defined range of LEDs where the LED that is switched on is equal to the led_1 variable, the other if statement works precisely the same using led_2. The code then uses the pause and the change function to increase the value of the variables. This allows a sequence of LEDs to be switched on. Once this variable has reached a set number the code resets the variable back to 0 and the indicator can begin again.

The pause function changes the speed on the indicators and increasing the value in the pause will make the indicator slower and decreasing will speed up the indicators. Feel free to play around with those values to change your indicators!

 

Downloads:

You can either produce the code yourself, using the screengrabs above as a guide or download the zip file below which contains the code for the indicators, one hex file for the :MOVE mini and one for the controller microbit. Once you unzip the file you can either drop it straight onto micro:bit in file explorer or drop it into the MakeCode Editor for tweaking/viewing.

  • You can download the file here.
Electronic Project Kits
← Previous Post Next Post →

Leave a Reply