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
The ported code is below. It’s not a complete port I have added a clause when the robot sees 2 black lines it will go backwards. The method below was added to the ported code found here (under a new tab). Create a new tab and name it _01_LineFollower, select the new tab and paste the below code into the IDE.
I then added the following line in the void loop() method in the tab named _00_programLoop;
Now were using Arduino IDE we have freed up a lot of memory we can write a more complicated line following algorithm. The above algorithm is as simple as it gets for this stuff, in the near future I will add a much more complicated line follower algorithm.
You can download the full code from the resources section or by clicking Bitbot_Lib_LF.