Software
Now that our robot is built and ready for action, it is time to write the Arduino program to bring it to life. With everything that we have covered in the past chapters under our belt, this will be the easy part.
Overview
Before we dive into writing the code, let us define the desired behavior of our robot and how we would like to control it. When the robot is powered on, it is in Manual control mode and you can drive it around via Bluetooth with an emulated control pad on your smartphone. We will use the Adafruit Bluefruit Connect app for this purpose, which we already got to know in the previous chapter. If we tap the 2 button, the robot switches to Line following mode and autonomously follows a black line on the ground (if there is one). If it loses the line, it should stop. By tapping the 1 button, we can bring the robot back under manual control.
Motor control
Since we have two motors and certainly do not want to write the same motor control code twice, we...