-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCC_Leo_Switch.ino
136 lines (114 loc) · 3.6 KB
/
CC_Leo_Switch.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Original https://github.com/MHeironimus/ArduinoJoystickLibrary (1.0 branch)
// The purpose of this modified version is for use with a Nintendo Switch and Wii Classic Controller.
//--------------------------------------------------------------------
// NOTE: This sketch file is for use with Arduino Leonardo and
// Arduino Micro only.
//
// by Matthew Heironimus
// 2016-11-24
//--------------------------------------------------------------------
#include <Joystick.h>
#include <NintendoExtensionCtrl.h>
ClassicController classic;
bool mashDownMode = false;
int mashValue = 0;
void setup() {
Serial.begin(115200);
Joystick.begin(false);
classic.begin();
while (!classic.connect()) {
Serial.println("Classic Controller not detected!");
delay(1000);
}
}
int rightStick(uint8_t input) {
if (input > 24)
return 127;
else if (input > 20)
return 64;
else if (input < 8)
return -127;
else if (input < 12)
return -64;
return 0;
}
int leftStick(uint8_t input) {
if (input > 45)
return 127;
else if (input > 35)
return 64;
else if (input < 15)
return -127;
else if (input < 25)
return -64;
return 0;
}
void loop() {
boolean success = classic.update();
if (!success) {
//Serial.println("Controller disconnected!");
classic.reconnect();
//delay(100);
} else {
//classic.printDebug();
if (classic.buttonHome()) {
//Modifier
Joystick.setButton(12, classic.buttonPlus()); //Home
Joystick.setButton(13, classic.buttonMinus()); //Capture
if (classic.buttonA()) {
mashDownMode = true;
} else if (classic.buttonB()) {
mashDownMode = false;
Joystick.setYAxis(0);
}
} else {
if (mashDownMode) {
mashValue += 10;
if(mashValue > 127)
mashValue = 0;
Joystick.setXAxis(0);
Joystick.setYAxis(mashValue);
Joystick.setZAxis(0);
Joystick.setZAxisRotation(0);
} else {
Joystick.setButton(2, classic.buttonA());
Joystick.setButton(1, classic.buttonB());
Joystick.setButton(3, classic.buttonX());
Joystick.setButton(0, classic.buttonY());
Joystick.setButton(4, classic.buttonL());
Joystick.setButton(5, classic.buttonR());
Joystick.setButton(6, classic.buttonZL());
Joystick.setButton(7, classic.buttonZR());
Joystick.setButton(9, classic.buttonPlus());
Joystick.setButton(8, classic.buttonMinus());
//Home has been changed to a modifier
Joystick.setXAxis(leftStick(classic.leftJoyX()));
Joystick.setYAxis(leftStick(classic.leftJoyY()) * -1);
Joystick.setZAxis(rightStick(classic.rightJoyX()));
Joystick.setZAxisRotation(rightStick(classic.rightJoyY()) * -1);
if (classic.dpadUp()) {
if (classic.dpadLeft())
Joystick.setHatSwitch(7);
else if (classic.dpadRight())
Joystick.setHatSwitch(1);
else
Joystick.setHatSwitch(0);
} else if (classic.dpadDown()) {
if (classic.dpadLeft())
Joystick.setHatSwitch(5);
else if (classic.dpadRight())
Joystick.setHatSwitch(3);
else
Joystick.setHatSwitch(4);
} else if (classic.dpadRight())
Joystick.setHatSwitch(2);
else if (classic.dpadLeft())
Joystick.setHatSwitch(6);
else
Joystick.setHatSwitch(-1);
}
}
}
Joystick.sendState();
delay(1);
}