Go to https://bitbot.l33t.uk/arduino-ide/ultrasonic-example-arduino-ide for instructions on how to configure Arduino IDE for use with the BBC Micro:bit if you haven’t already. This code builds on the code found at https://bitbot.l33t.uk/arduino-ide/porting-bitbot-code-from-micropython-to-c
I have added code for a light seeking robot. I saw little point to create code for a light avoider; the code is similar just inverted. I opened the previous project and created a new tab called _02_LightSensitive and added the below code;
I then called the startLightSensitive() method from the loop() method in the _00_programLoop tab.
Colours are the same Cyan = rooms too bright, Pink = waiting for light, Green = following light.
The code for this can be downloaded here Bitbot_Lib_LightSS.zip or the resources section.