Advertisement
LeventeDaradici

180 degree sliding servo

Dec 29th, 2021
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. // Include the Servo library
  2. #include <Servo.h>
  3. // Declare the Servo pin
  4. int servoPin = 3;
  5. // Create a servo object
  6. Servo Servo1;
  7. void setup() {
  8. // We need to attach the servo to the used pin number
  9.    Servo1.attach(servoPin);
  10. }
  11. void loop(){
  12. for(int i = 0; i <= 180; i++)
  13.    {Servo1.write(i);
  14.      delay(200);
  15.    }  
  16. for(int i = 180; i >= 0; i--)
  17.    {Servo1.write(i);
  18.      delay(200);
  19.    }  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement