3333
3434ClassicController classic;
3535
36+ const int RangeOffset = 45 ; // to make sure the values reach min/max outputs
37+ const int RangeMin = 0 + RangeOffset;
38+ const int RangeMax = 255 - RangeOffset;
39+
3640void setup () {
3741 classic.begin ();
3842
39- XInput.setTriggerRange (4 , 26 );
43+ XInput.setTriggerRange (RangeMin, RangeMax); // set both left and right
4044
41- XInput.setRange (JOY_LEFT, 8 , 56 );
42- XInput.setRange (JOY_RIGHT, 4 , 28 );
45+ XInput.setRange (JOY_LEFT, RangeMin, RangeMax );
46+ XInput.setRange (JOY_RIGHT, RangeMin, RangeMax );
4347
4448 XInput.setAutoSend (false ); // Wait for all controls before sending
4549
@@ -52,7 +56,7 @@ void setup() {
5256
5357void loop () {
5458 if (classic.update ()) { // Get new data!
55- XInput.setJoystick (JOY_LEFT, classic.leftJoyX (), classic.leftJoyY ());
59+ XInput.setJoystick (JOY_LEFT, classic.leftJoyX (), classic.leftJoyY ());
5660 XInput.setJoystick (JOY_RIGHT, classic.rightJoyX (), classic.rightJoyY ());
5761
5862 XInput.setButton (BUTTON_A, classic.buttonB ());
@@ -61,25 +65,28 @@ void loop() {
6165 XInput.setButton (BUTTON_Y, classic.buttonX ());
6266
6367 XInput.setButton (BUTTON_START, classic.buttonPlus ());
64- XInput.setButton (BUTTON_BACK, classic.buttonMinus ());
65- XInput.setButton (BUTTON_LOGO, classic.buttonHome ());
68+ XInput.setButton (BUTTON_BACK, classic.buttonMinus ());
69+ XInput.setButton (BUTTON_LOGO, classic.buttonHome ());
6670
6771 XInput.setDpad (classic.dpadUp (), classic.dpadDown (), classic.dpadLeft (), classic.dpadRight ());
6872
69- XInput.setTrigger (TRIGGER_LEFT, classic.triggerL ());
73+ XInput.setTrigger (TRIGGER_LEFT, classic.triggerL ());
7074 XInput.setTrigger (TRIGGER_RIGHT, classic.triggerR ());
7175
7276 XInput.setButton (BUTTON_LB, classic.buttonZL ());
7377 XInput.setButton (BUTTON_RB, classic.buttonZR ());
7478
7579 // XInput.setButton(BUTTON_L3, classic.buttonZL()); // The Classic Controller doesn't have L3 and R3
7680 // XInput.setButton(BUTTON_R3, classic.buttonZR()); // but you can uncomment these to check that they work
81+
82+ XInput.send ();
7783 }
7884 else { // Data is bad :(
79- XInput.releaseAll (); // clear set inputs
80- classic.connect (); // attempt to reconnect
81- delay (1000 );
82- }
85+ XInput.releaseAll (); // clear set inputs...
86+ XInput.send (); // ...and send that update
8387
84- XInput.send ();
88+ while (!classic.connect ()) { // attempt to reconnect
89+ delay (1000 );
90+ }
91+ }
8592}
0 commit comments