Advertisement
inagantid20

Motor and Potentiometer Code

Jun 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /*
  2. *Divya Inaganti
  3. *June 19, 2017
  4. *Motor and Potentiometer
  5. */
  6. #include <Servo.h>
  7. Servo miServito;
  8. const int PotPin= A0;
  9. int PotValue;
  10. int angle;
  11. void setup()
  12. {
  13. pinMode(PotPin, INPUT);
  14. miServito.attach(9);
  15. Serial.begin(9600);
  16.  
  17. }
  18.  
  19. void loop() {
  20. {
  21. PotValue= analogRead(PotPin);
  22. angle= map(PotValue, 0 , 1023, 0, 179);
  23. angle= constrain(angle, 0, 179);
  24. miServito.write(angle);
  25. miServito.write(0);
  26. delay (500);
  27. miServito.write(45);
  28. delay(500);
  29. miServito.write(90);
  30. delay (500);
  31. miServito.write(135);
  32. delay(500);
  33. miServito.write(180);
  34. delay(500);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement