Advertisement
zoro-10

Servo Motor

Apr 1st, 2024 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. https://imgur.com/a/IoYvF4z
  2.  
  3.  
  4. #include <Servo.h>
  5. Servo servoBase; // Create a Servo object and assign it a specific name
  6. void setup()
  7. {
  8.   servoBase.attach(A1); // Specify the pin to use for the servo
  9.   servoBase.write(0);   // Set the servo motor to the 0-degree position
  10. }
  11. void loop()
  12. {
  13.   // Sweep the servo from 0 to 180 degrees in steps of 10 degrees
  14.   for (int i = 0; i <= 180; i += 10)
  15.   {
  16.     servoBase.write(i); // Set the servo to the current angle
  17.     delay(2000);        // Pause for 2000 milliseconds (2 seconds)
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement