- #include <Servo.h>
-
- Servo myservo0; // create servo object to control a servo
- Servo myservo1;
- Servo myservo2;
- Servo myservo3;
- Servo myservo4;
- Servo myservo5;
-
- int pos = 0; // variable to store the servo position
-
- void setup()
- {
- myservo0.attach(0); // attaches the servo on pin 9 to the servo object
- myservo1.attach(1);
- myservo2.attach(2);
- myservo3.attach(3);
- myservo4.attach(4);
- myservo5.attach(4);
- }
-
-
- void loop()
- {
- for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
- { // in steps of 1 degree
- myservo0.write(pos); // tell servo to go to position in variable 'pos'
- myservo1.write(pos);
- myservo2.write(pos);
- myservo3.write(pos);
- myservo4.write(pos);
- myservo5.write(pos);
- delay(10); // waits 15ms for the servo to reach the position
- }
- for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
- {
- myservo0.write(pos); // tell servo to go to position in variable 'pos'
- myservo1.write(pos);
- myservo2.write(pos);
- myservo3.write(pos);
- myservo4.write(pos);
- myservo5.write(pos);
- delay(10); // waits 15ms for the servo to reach the position
- }
- }
复制代码
控制舵机速度就修改一下for里的delay时间 |