Chapter 2. Coding
The code that controls your robot is simple. Well, it’s simpler than one would expect for a sci-fi trick like mind control.
A simplified, pseudocode version of your robot would be as follows:
void loop()
{
while (lineDetected()) turn(); //
forward(getAttention()); //
}Rinse and repeat.
In this coding part of the book, you’ll write each part of the code that makes your robot tick.
Moving
Continuous rotation servos are motors you can easily control. With continuous rotation servos, you can only control the speed (forward, stop, back), but unlike standard servos, you can’t set the servo to point at a specific angle.
There are three wires going to a servo: red (positive), black (ground), and white (data). To control a servo, you need to keep sending pulses to it. The length of the pulse tells how fast the full rotation servo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access