Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void setup() {
- // configure the joystick to manual send mode. This gives precise
- // control over when the computer receives updates, but it does
- // require you to manually call Joystick.send_now().
- Joystick.useManualSend(true);
- pinMode(0, INPUT_PULLUP);
- pinMode(2, INPUT_PULLUP);
- pinMode(3, INPUT_PULLUP);
- pinMode(4, INPUT_PULLUP);
- pinMode(5, INPUT_PULLUP);
- pinMode(6, INPUT_PULLUP);
- pinMode(7, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(14, INPUT_PULLUP);
- pinMode(15, INPUT_PULLUP);
- pinMode(16, INPUT_PULLUP);
- pinMode(17, INPUT_PULLUP);
- pinMode(18, INPUT_PULLUP);
- pinMode(19, INPUT_PULLUP);
- pinMode(20, INPUT_PULLUP);
- pinMode(21, INPUT_PULLUP);
- }
- void loop() {
- Joystick.X(analogRead(23));
- Joystick.Y(1023 - analogRead(22));
- Joystick.Z(1023 - analogRead(25));
- Joystick.Zrotate(1023 - analogRead(24));
- Joystick.button(1, digitalRead(2) == LOW); //A
- Joystick.button(2, digitalRead(3) == LOW); //B
- Joystick.button(3, digitalRead(5) == LOW); //X
- Joystick.button(4, digitalRead(4) == LOW); //Y
- Joystick.button(5, digitalRead(16) == LOW); //LBump
- Joystick.button(6, digitalRead(6) == LOW); //RBump
- Joystick.button(7, digitalRead(14) == LOW); //Select
- Joystick.button(8, digitalRead(8) == LOW); //Start
- Joystick.button(9, digitalRead(21) == LOW); //L3
- Joystick.button(10, digitalRead(0) == LOW); //R3
- Joystick.button(11, digitalRead(15) == LOW); //LTrig
- Joystick.button(12, digitalRead(7) == LOW); //RTrig
- int up = digitalRead(17) == LOW;
- int down = digitalRead(19) == LOW;
- int left = digitalRead(20) == LOW;
- int right = digitalRead(18) == LOW;
- int angle = -1;
- if (up)
- {
- if (left)
- {
- angle = 315;
- }
- else if (right)
- {
- angle = 45;
- }
- else
- {
- angle = 0;
- }
- }
- else if (down)
- {
- if (left)
- {
- angle = 225;
- }
- else if (right)
- {
- angle = 135;
- }
- else
- {
- angle = 180;
- }
- }
- else if (left)
- {
- angle = 270;
- }
- else if (right)
- {
- angle = 90;
- }
- Joystick.hat(angle);
- // Because setup configured the Joystick manual send,
- // the computer does not see any of the changes yet.
- // This send_now() transmits everything all at once.
- Joystick.send_now();
- // a brief delay, so this runs "only" 125 times per second
- delay(8);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement