Advertisement
DanielKrastev-bit

servo hello world

Mar 27th, 2024
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myServo;  // Create a servo object to control a servo
  4.  
  5. int servoPin = 9;  // Pin connected to the servo
  6.  
  7. void setup() {
  8.   myServo.attach(servoPin);  // Attach the servo to the pin
  9. }
  10.  
  11. void loop() {
  12.   // Move the servo to the starting position (0 degrees)
  13.   myServo.write(0);
  14.   delay(1000);  // Wait for 1 second
  15.  
  16.   // Move the servo to the middle position (90 degrees)
  17.   myServo.write(90);
  18.   delay(1000);  // Wait for 1 second
  19.  
  20.   // Move the servo to the end position (180 degrees)
  21.   myServo.write(180);
  22.   delay(1000);  // Wait for 1 second
  23.   // Move the servo to the middle position (90 degrees)
  24.   myServo.write(90);
  25.   delay(1000);  // Wait for 1 second
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement