Guest User

Untitled

a guest
Apr 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // include the servo library
  2. #include <Servo.h>
  3.  
  4. // creates an instance of the servo object to control a servo
  5. Servo myservo;
  6.  
  7. // declare the control pin for servo motor, call it servoPin
  8. int servopin = A0;
  9. int angle;
  10.  
  11. void setup() {
  12. // initialize serial communications
  13. Serial.begin(9600);
  14.  
  15. // attach the servo object to the servoPin
  16. myservo.attach(3);
  17. }
  18.  
  19. void loop() {
  20. // read the analog input
  21. angle = analogRead(servopin);
  22.  
  23. // print it to the serial monitor
  24. Serial.println(servopin);
  25.  
  26. // make a new int called angle - use the map() function to map the range of your sensor to the range of the servo (which is 0 to 179)
  27. angle = map(angle, 0, 1023, 0, 180);
  28. // move the servo using the angle from the sensor with the servo write() function
  29. myservo.write(angle);
  30. delay(20);
  31. }
Add Comment
Please, Sign In to add comment