Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo1; // create servo object to control a servo
  4. Servo myservo2; // create servo object to control a servo
  5. Servo myservo3; // create servo object to control a servo
  6. int pos = 0; // variable to store the servo position
  7.  
  8. void setup() {
  9. myservo1.attach(9); // attaches the servo on pin 9 to the servo object
  10. myservo2.attach(10); // attaches the servo on pin 9 to the servo object
  11. myservo3.attach(11); // attaches the servo on pin 9 to the servo object
  12.  
  13. }
  14.  
  15. void loop() {
  16. for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
  17. myservo1.write(pos); // tell servo to go to position in variable 'pos'
  18. myservo2.write(pos); // tell servo to go to position in variable 'pos'
  19. myservo3.write(pos); // tell servo to go to position in variable 'pos'
  20. delay(15); // waits 15ms for the servo to reach the position
  21. }
  22. for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  23. myservo1.write(pos); // tell servo to go to position in variable 'pos'
  24. myservo2.write(pos); // tell servo to go to position in variable 'pos'
  25. myservo3.write(pos); // tell servo to go to position in variable 'pos'
  26. delay(15); // waits 15ms for the servo to reach the position
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement