Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. /*
  2.  
  3. */
  4. int potPin = 2;
  5. int ms = 7;
  6. bool isHigh = false;
  7. double pwmval = 0.0;
  8. Servo victor;
  9. int victorpin = 10;
  10. bool runonce = true;
  11. void setup() {
  12. Serial.begin(9800);
  13. victor.attach(victorpin);
  14. pinMode(ms, INPUT);
  15. }
  16.  
  17. void loop() {
  18. pwmval = analogRead(potPin);
  19.  
  20. isHigh = (digitalRead(ms) == HIGH);
  21.  
  22. if (isHigh) {
  23. pwmval *= -1;
  24. }
  25.  
  26. pwmval = map(pwmval, -1023, 1023, 0, 180);
  27.  
  28. victor.write(pwmval);
  29. }
  30.  
  31. void pwmcalibration() {
  32. if (runonce) {
  33. victor.write(180);
  34. delay(2000);
  35. victor.write(0);
  36. delay(2000);
  37. victor.write(90);
  38. delay(2000);
  39. runonce = false;
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement