Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Joystick.h>
  2.  
  3. Joystick_ Joystick;
  4.  
  5. int xAxis_ = 0;
  6. int yAxis_ = 0;
  7. int zAxis_ = 0;
  8. int RxAxis_ = 0;
  9. int RyAxis_ = 0;
  10. int RzAxis_ = 0;
  11. int Throttle_ = 0;
  12. const int armAndStage = 2;
  13. const int abortButton = 3;
  14. const int rcsSwitch = 5;
  15. const int sasSwitch = 6;
  16. const int lightsButton = 7;
  17. const int gearsButton = 8;
  18. const int solarButton = 9;
  19. const int escButton = 10;
  20. const int timeUp = 11;
  21. const int timeDown = 12;
  22.  
  23. const bool initAutoSendState = true;
  24.  
  25. void setup() {
  26.   pinMode(armAndStage, INPUT);
  27.   pinMode(abortButton, INPUT_PULLUP);
  28.   pinMode(sasSwitch, INPUT_PULLUP);
  29.   pinMode(rcsSwitch, INPUT_PULLUP);
  30.   pinMode(lightsButton, INPUT_PULLUP);
  31.   pinMode(gearsButton, INPUT_PULLUP);
  32.   pinMode(solarButton, INPUT_PULLUP);
  33.   pinMode(escButton, INPUT_PULLUP);
  34.   pinMode(timeUp, INPUT_PULLUP);
  35.   pinMode(timeDown, INPUT_PULLUP);
  36.   Joystick.begin();
  37. }
  38.  
  39. void loop() {
  40.   controls();
  41. }
  42.  
  43. void controls(void) {
  44.  
  45.   if (digitalRead(armAndStage) == HIGH) {
  46.     Joystick.pressButton(armAndStage);
  47.   }
  48.   else {
  49.     Joystick.releaseButton(armAndStage);
  50.   }
  51.  
  52.   if (digitalRead(abortButton) == LOW) {
  53.     Joystick.pressButton(abortButton);
  54.   }
  55.   else {
  56.     Joystick.releaseButton(abortButton);
  57.   }
  58.  
  59.   if (digitalRead(rcsSwitch == LOW)) {
  60.     Joystick.pressButton(rcsSwitch);
  61.   }
  62.   else {
  63.     Joystick.releaseButton(rcsSwitch);
  64.   }
  65.  
  66.   if (digitalRead(sasSwitch) == LOW) {
  67.     Joystick.pressButton(sasSwitch);
  68.   }
  69.   else {
  70.     Joystick.releaseButton(sasSwitch);
  71.   }
  72.  
  73.   if (digitalRead(lightsButton) == LOW) {
  74.     Joystick.pressButton(lightsButton);
  75.   }
  76.   else {
  77.     Joystick.releaseButton(lightsButton);
  78.   }
  79.  
  80.   if (digitalRead(gearsButton) == LOW) {
  81.     Joystick.pressButton(gearsButton);
  82.   }
  83.   else {
  84.     Joystick.releaseButton(gearsButton);
  85.   }
  86.  
  87.   if (digitalRead(solarButton) == LOW) {
  88.     Joystick.pressButton(solarButton);
  89.   }
  90.   else {
  91.     Joystick.releaseButton(solarButton);
  92.   }
  93.  
  94.   if (digitalRead(escButton) == LOW) {
  95.     Joystick.pressButton(escButton);
  96.   }
  97.   else {
  98.     Joystick.releaseButton(escButton);
  99.   }
  100.  
  101.   if (digitalRead(timeUp) == LOW) {
  102.     Joystick.pressButton(timeUp);
  103.   }
  104.   else {
  105.     Joystick.releaseButton(timeUp);
  106.   }
  107.  
  108.   if (digitalRead(timeDown) == LOW) {
  109.     Joystick.pressButton(timeDown);
  110.   }
  111.   else {
  112.     Joystick.releaseButton(timeDown);
  113.   }
  114.  
  115.   xAxis_ = analogRead(A0);
  116.   xAxis_ = map(xAxis_,1023,0,255,0);
  117.   Joystick.setXAxis(xAxis_);
  118.  
  119.   yAxis_ = analogRead(A1);
  120.   yAxis_ = map(yAxis_,0,1023,0,255);
  121.   Joystick.setYAxis(yAxis_);
  122.  
  123.   zAxis_ = analogRead(A2);
  124.   zAxis_ = map(zAxis_,0,1023,0,255);
  125.   Joystick.setZAxis(zAxis_);
  126.  
  127.   RxAxis_ = analogRead(A3);
  128.   RxAxis_ = map(RxAxis_,0,1023,0,255);
  129.   Joystick.setRxAxis(RxAxis_);
  130.  
  131.   RyAxis_ = analogRead(A4);
  132.   RyAxis_ = map(RyAxis_,0,1023,0,255);
  133.   Joystick.setRyAxis(RyAxis_);
  134.  
  135.   RzAxis_ = analogRead(A5);
  136.   RzAxis_ = map(RzAxis_,0,1023,0,255);
  137.   Joystick.setRzAxis(RzAxis_);
  138.  
  139.   Throttle_ = analogRead(A6);
  140.   Throttle_ = map(Throttle_,0,1023,0,255);
  141.   Joystick.setThrottle(Throttle_);
  142.  
  143.   delay (10);
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement