Instructions
25/06/2015 DFRduinoBeginnerKitForArduinoV3SKU:DFR0100RobotWiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100 13/23
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//MovingaServo
//byBARRAGAN<http://barraganstudio.com>
//Thisexamplecodeisinthepublicdomain.
#include<Servo.h>
Servomyservo;//createservoobjecttocontrolaservo
//amaximumofeightservoobjectscanbecreated
intpos=0;//variabletostoretheservoposition
voidsetup(){
myservo.attach(9);//attachestheservoonpin9totheservoobject
}
voidloop(){
for(pos=0;pos<180;pos+=1){//goesfrom0degreesto180degrees
//instepsof1degree
myservo.write(pos);//tellservotogotopositioninvariable'pos'
delay(15);//waits15msfortheservotoreachtheposition
}
for(pos=180;pos>=1;pos‐=1){//goesfrom180degreesto0
degrees
myservo.write(pos);//tellservotogotopositioninvariable'pos'
delay(15);//waits15msfortheservotoreachtheposition
}
}