
www.sunfounder.com
45
Thus we can make it automatically carry blocks continuously:
6.3
Code Explanation
The program includes three parts: rotating the potentiometers to control the Rollarm,
pressing the button slightly for less than one second to record Rollarm’s behaviors and
pressing the button for a relatively longer time to make Rollarm repeat the recorded steps.
There are four potentiometers to control the arms. The 4 servos from top to bottom are
connected to port 4-7 respectively of the expansion board, and the 4 potentiometers
control the ports accordingly. In other words, spin the white potentiometer to control the
uppermost servo, the yellow to control the next servo below, the orange to control the next
servo, and the red one to control the bottom servo.
Since the Rollarm has four servos acting as the moving joint, we need to include a header
file for driving the servos and define them.
// Create servo object to control a servo.
#include <Servo.h>
Servo Servo_0
;
Servo Servo_1
;
Servo Servo_2
;