DFRobot DFR0100 Manual page 13

Beginner kit for arduino v3
Table of Contents

Advertisement

25/06/2015
?
// Moving a Servo
1
// by BARRAGAN <http://barraganstudio.com>
2
// This example code is in the public domain.
3
 
4
#include <Servo.h>    
5
Servo myservo;         // create servo object to control a servo
6
                       // a maximum of eight servo objects can be created
7
 
int
pos = 0;            // variable to store the servo position
8
 
 
9
 
void
setup() {
10
    myservo.attach(9);  // attaches the servo on pin 9 to the servo object
11
}
12
 
 
13
 
void
loop() {
14
    for(pos = 0; pos < 180; pos += 1){   // goes from 0 degrees to 180 degrees
15
                                         // in steps of 1 degree    
16
        myservo.write(pos);              // tell servo to go to position in variable 'pos'   
17
        delay(15);                       // waits 15ms for the servo to reach the position
18
    }
19
 
    
20
    for(pos = 180; pos>=1; pos‐=1) {     // goes from 180 degrees to 0
21
degrees                               
22
        myservo.write(pos);              // tell servo to go to position in variable 'pos' 
23
        delay(15);                       // waits 15ms for the servo to reach the position
24
    }
25
}
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100
DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 ­ Robot Wiki
13/23

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the DFR0100 and is the answer not in the manual?

Table of Contents