SHARE
TWEET

JoyStick/DoubleServoMotor control

a guest Dec 15th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top