
36 Make: Robotic Arms
STEP 12: TESTING OUR MOTORS
#include <Servo.h>
Servo servoOne;
Servo servoTwo;
int randomOne;
int randomTwo;
void setup() {
servoOne.attach(3);
servoTwo.attach(5);
randomSeed(analogRead(A0));
randomOne = random(45,90);
randomTwo = random(90,180);
servoOne.write(randomOne);
servoTwo.write(randomTwo);
}
void loop() {
}
Here, in this first test code, what we’ve written
looks a lot like our previous example. This time,
however, there’s one key difference: the code
we need to generate random numbers we can
then use as input angles for our .write()
commands for our servos. The first few lines of
code establish our servos, just like before. In ...