Guest User

Untitled

a guest
Apr 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. // Aidan Rafferty
  2. // Object Lab 05
  3. // 4/10/18
  4.  
  5. // include the servo library
  6. #include <Servo.h>
  7.  
  8. // creates an instance of the servo object to control a servo
  9. Servo myServo;
  10. // declare the control pin for servo motor, call it servoPin
  11. #define servoPin 6
  12.  
  13. void setup() {
  14. // initialize serial communications
  15. Serial.begin(9600);
  16. // attach the servo object to the servoPin
  17. // pinMode(servoPin, OUTPUT);
  18. myServo.attach(servoPin);
  19. }
  20.  
  21. void loop() {
  22. // read the analog input
  23. int sensor = analogRead(A0);
  24. // print it to the serial monitor
  25. Serial.println(sensor);
  26.  
  27. // 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)
  28. int angle = map(sensor, 0, 1024, 0, 179);
  29.  
  30. // move the servo using the angle from the sensor with the servo write() function
  31. myServo.write(angle);
  32. delay(20);
  33.  
  34. }
Add Comment
Please, Sign In to add comment