Advertisement
Guest User

Untitled

a guest
May 27th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo; // create servo object
  4.  
  5. // variable to hold servo angle
  6. int angle = 0;
  7.  
  8. int pot = 0; // for potentiometer reading
  9.  
  10. void setup() {
  11. // attach the servo motor
  12. myservo.attach(6);
  13. Serial.begin(9600);
  14. }
  15.  
  16. void loop() {
  17. // read the potentiometer
  18. pot = analogRead(A0);
  19. // pot will be value between 0-1023
  20. // servo accepts values between 0-180
  21. Serial.println(pot);
  22. angle = map(pot, 0, 1023, 0, 180);
  23. myservo.write(angle);
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement