Advertisement
lutermana

Servo Motor with Potentiometer

Sep 29th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo MyServito;
  3. const int PotPin = A0;
  4. const int ServoPin= 9;
  5. int PotVal= 0;
  6. int angle = 0;
  7.  
  8. void setup() {
  9. pinMode(PotPin, INPUT);
  10. MyServito.attach(ServoPin);
  11. Serial.begin(9600);
  12.  
  13. }
  14.  
  15. void loop() {
  16. PotVal = analogRead(PotPin);
  17. angle = map(PotVal, 0, 1023, 0, 179);
  18. angle = constrain(angle, 0, 179);
  19. MyServito.write(angle); //figures out how to write to the Servito-- dont need to specify what pin # is
  20. delay(15);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement