Hardware 30
Hardware
This is the rst function in the Sweep example. The pos=0 is the position we are starting from which in this
case we wrote as 0 degrees. The second part is telling the motor to move a total of 180 degrees. Now we
need to tell it to stop. We can write that as:
myservo.write(pos);
delay(15);
This part tells the motor to stop and wait for a total of 15 milliseconds.
To tell the motor to go move back the other direction, we have to change it’s starting position from 0 de-
grees to where we left it 180 degrees. That is written like this:
for(pos=180;pos>=1;pos-=1)
Challenge
Play around with the Sweep code, how could you make the motor go faster? Change the delay and de-
grees of movement. Think about how you would want your robot to move, how can you reect the move-
ments you want to make through this code?
Lesson 4, Figure 9