Advertisement
Guest User

Untitled

a guest
Oct 18th, 2021
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.39 KB | None | 0 0
  1. void setup() {
  2.   // configure the joystick to manual send mode.  This gives precise
  3.   // control over when the computer receives updates, but it does
  4.   // require you to manually call Joystick.send_now().
  5.   Joystick.useManualSend(true);
  6.  
  7.   pinMode(0, INPUT_PULLUP);
  8.   pinMode(2, INPUT_PULLUP);
  9.   pinMode(3, INPUT_PULLUP);
  10.   pinMode(4, INPUT_PULLUP);
  11.   pinMode(5, INPUT_PULLUP);
  12.   pinMode(6, INPUT_PULLUP);
  13.   pinMode(7, INPUT_PULLUP);
  14.   pinMode(8, INPUT_PULLUP);
  15.   pinMode(14, INPUT_PULLUP);
  16.   pinMode(15, INPUT_PULLUP);
  17.   pinMode(16, INPUT_PULLUP);
  18.   pinMode(17, INPUT_PULLUP);
  19.   pinMode(18, INPUT_PULLUP);
  20.   pinMode(19, INPUT_PULLUP);
  21.   pinMode(20, INPUT_PULLUP);
  22.   pinMode(21, INPUT_PULLUP);
  23. }
  24.  
  25. void loop() {
  26.   Joystick.X(analogRead(23));
  27.   Joystick.Y(1023 - analogRead(22));
  28.   Joystick.Z(1023 - analogRead(25));
  29.   Joystick.Zrotate(1023 - analogRead(24));
  30.  
  31.   Joystick.button(1, digitalRead(2) == LOW); //A
  32.   Joystick.button(2, digitalRead(3) == LOW); //B
  33.   Joystick.button(3, digitalRead(5) == LOW);  //X
  34.   Joystick.button(4, digitalRead(4) == LOW);  //Y
  35.   Joystick.button(5, digitalRead(16) == LOW);  //LBump
  36.   Joystick.button(6, digitalRead(6) == LOW);  //RBump
  37.   Joystick.button(7, digitalRead(14) == LOW);  //Select
  38.   Joystick.button(8, digitalRead(8) == LOW);  //Start
  39.   Joystick.button(9, digitalRead(21) == LOW);  //L3
  40.   Joystick.button(10, digitalRead(0) == LOW);  //R3
  41.   Joystick.button(11, digitalRead(15) == LOW);  //LTrig
  42.   Joystick.button(12, digitalRead(7) == LOW);  //RTrig
  43.  
  44.   int up = digitalRead(17) == LOW;
  45.   int down = digitalRead(19) == LOW;
  46.   int left = digitalRead(20) == LOW;
  47.   int right = digitalRead(18) == LOW;
  48.   int angle = -1;
  49.   if (up)
  50.   {
  51.     if (left)
  52.     {
  53.       angle = 315;
  54.     }
  55.     else if (right)
  56.     {
  57.       angle = 45;
  58.     }
  59.     else
  60.     {
  61.       angle = 0;
  62.     }
  63.   }
  64.   else if (down)
  65.   {
  66.     if (left)
  67.     {
  68.       angle = 225;
  69.     }
  70.     else if (right)
  71.     {
  72.       angle = 135;
  73.     }
  74.     else
  75.     {
  76.       angle = 180;
  77.     }
  78.   }
  79.   else if (left)
  80.   {
  81.     angle = 270;
  82.   }
  83.   else if (right)
  84.   {
  85.     angle = 90;
  86.   }
  87.   Joystick.hat(angle);
  88.  
  89.   // Because setup configured the Joystick manual send,
  90.   // the computer does not see any of the changes yet.
  91.   // This send_now() transmits everything all at once.
  92.   Joystick.send_now();
  93.  
  94.   // a brief delay, so this runs "only" 125 times per second
  95.   delay(8);
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement