Advertisement
iyera20

Servo Motor

Jun 20th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /*
  2. * Atiriya Iyer
  3. * 6-19-17
  4. * Servo Motor
  5. */
  6. # include <Servo.h>
  7.  
  8. Servo miServito;
  9.  
  10. const int PotPin= A0;
  11. int PotVal;
  12. int angle;
  13.  
  14. void setup()
  15. {
  16. // put your setup code here, to run once:
  17. pinMode (PotPin, INPUT);
  18. miServito.attach (9);
  19. Serial.begin (9600);
  20. }
  21.  
  22. void loop()
  23. {
  24. // put your main code here, to run repeatedly:
  25. PotVal = (analogRead (PotPin));
  26. angle= map (PotVal, 0, 1023, 0, 360);
  27. angle= constrain (angle, 0, 360);
  28. miServito.write (angle);
  29.  
  30. //miServito.write(90);
  31. //delay(300);
  32. //miServito.write(180);
  33. //delay(300);
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement