Guest User

Untitled

a guest
Oct 20th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <Servo.h> //For driving the ESCs and Servos
  2. #include <PS2X_lib.h> // Bill Porter's PS2X Library
  3.  
  4. PS2X ps2x; //The PS2 Controller Class
  5.  
  6. Servo UpRServo; //Create servo object representing up right ESC
  7.  
  8.  
  9. int RollLeftVal = 0; //Value read off the PS2 Left Stick left/right
  10.  
  11.  
  12. //Variables to carry the actual raw data for the ESCs
  13. int upRraw = 0;
  14.  
  15.  
  16. void setup()
  17. {
  18. ps2x.config_gamepad(A0,A2,13,A1, true, false);
  19. //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?)
  20. //We have disabled the pressure sensitivity and rumble in this instance and
  21. //we know the controller type so we have not bothered with the error checks
  22.  
  23. UpRServo.attach(6);// attaches the Up Right Servo to pin 6
  24.  
  25. }
  26.  
  27. void loop()
  28. {
  29. ps2x.read_gamepad(); //This needs to be called at least once a second
  30. // to get data from the controller.
  31.  
  32.  
  33. //Analogue Stick readings
  34.  
  35. RollLeftVal = ps2x.Analog(PSS_LX);
  36.  
  37. //Variables to carry the actual raw data for the ESCs
  38.  
  39. upRraw = (127-RollLeftVal); //This will be up to a value of 192
  40.  
  41.  
  42. //Scale the values to be suitable for ESCs and Servos
  43.  
  44. upRraw=map(upRraw,-127,127,0,179);
  45.  
  46.  
  47. //Write it to the Servos or ESCs
  48.  
  49.  
  50. UpRServo.write(upRraw);
  51.  
  52.  
  53. delay(15);
  54. }
Add Comment
Please, Sign In to add comment