Advertisement
andretafta

Testing Servo

Aug 17th, 2020 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. Servo myservo;  // create servo object to control a servo
  4. // twelve servo objects can be created on most boards
  5.  
  6.  
  7. void setup() {
  8.   myservo.attach(2);  // attaches the servo on GIO2 to the servo object
  9. }
  10.  
  11. void loop() {
  12.   int pos;
  13.  
  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.   for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
  20.     myservo.write(pos);              // tell servo to go to position in variable 'pos'
  21.     delay(15);                       // waits 15ms for the servo to reach the position
  22.   }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement