Advertisement
Guest User

JoyStick/DoubleServoMotor control

a guest
Dec 15th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo servo1;
  4. Servo servo2;
  5. int joyX = 0;
  6. int joyY = 1;
  7.  
  8. int servoVal1,servoVal2;
  9.  
  10. void setup()
  11. {
  12. Serial.begin(9600);
  13. servo1.attach(10);
  14. servo2.attach(9);
  15. }
  16.  
  17. void loop()
  18. {
  19.  
  20. servoVal1 = analogRead(joyX);
  21.  
  22. servoVal1 = map(servoVal1, 0, 1023, 0, 180);
  23. servo1.write(servoVal1);
  24.  
  25. servoVal2 = analogRead(joyY);
  26. servoVal2 = map(servoVal2, 0, 1023, 0, 180);
  27. servo2.write(servoVal2);
  28.  
  29. Serial.println(servoVal2);
  30. delay(15);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement