Advertisement
manvi_m

Servo motor

Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. /*
  2. * Manvi Mittal
  3. * Servo program
  4. */
  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, 179);
  28. miServito.write (angle);
  29. Serial.println (PotPin);
  30.  
  31. miServito.write (90);
  32. delay (300);
  33. miServito.write (180);
  34. delay (300);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement