-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGC_Native.ino
More file actions
203 lines (174 loc) · 4.6 KB
/
Copy pathGC_Native.ino
File metadata and controls
203 lines (174 loc) · 4.6 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <SwitchControlLibrary.h>
// Button Pins
const int Pin_ButtonA = 4;
const int Pin_ButtonB = 6;
const int Pin_ButtonX = 5;
const int Pin_ButtonY = 7;
const int Pin_ButtonL = 8;
const int Pin_ButtonR = 3;
const int Pin_ButtonStart = 2;
const int Pin_DpadUp = 9;
const int Pin_DpadDown = 10;
const int Pin_DpadLeft = 12;
const int Pin_DpadRight = 11;
bool previousStateA = false;
unsigned long timeA;
bool previousStateB = false;
unsigned long timeB;
bool previousStateX = false;
unsigned long timeX;
bool previousStateY = false;
unsigned long timeY;
bool previousStateL = false;
unsigned long timeL;
bool previousStateR = false;
unsigned long timeR;
bool previousStateStart = false;
unsigned long timeStart;
Hat previousDPad = Hat::CENTER;
unsigned long timeDPad;
unsigned long timer = 5;
void setup() {
pinMode(Pin_ButtonA, INPUT);
pinMode(Pin_ButtonB, INPUT);
pinMode(Pin_ButtonX, INPUT);
pinMode(Pin_ButtonY, INPUT);
pinMode(Pin_ButtonL, INPUT);
pinMode(Pin_ButtonR, INPUT);
pinMode(Pin_ButtonStart, INPUT);
pinMode(Pin_DpadUp, INPUT);
pinMode(Pin_DpadDown, INPUT);
pinMode(Pin_DpadLeft, INPUT);
pinMode(Pin_DpadRight, INPUT);
SwitchControlLibrary().PressButtonPlus();
SwitchControlLibrary().ReleaseButtonPlus();
}
void loop() {
unsigned long currentMillis = millis();
boolean buttonA = !digitalRead(Pin_ButtonA);
boolean buttonB = !digitalRead(Pin_ButtonB);
boolean buttonX = !digitalRead(Pin_ButtonX);
boolean buttonY = !digitalRead(Pin_ButtonY);
boolean buttonL = !digitalRead(Pin_ButtonL);
boolean buttonR = !digitalRead(Pin_ButtonR);
boolean buttonStart = !digitalRead(Pin_ButtonStart);
boolean dpadUp = !digitalRead(Pin_DpadUp);
boolean dpadDown = !digitalRead(Pin_DpadDown);
boolean dpadLeft = !digitalRead(Pin_DpadLeft);
boolean dpadRight = !digitalRead(Pin_DpadRight);
if(buttonA != previousStateA && currentMillis - timeA > timer)
{
if(buttonA)
SwitchControlLibrary().PressButtonA();
else
SwitchControlLibrary().ReleaseButtonA();
previousStateA = buttonA;
timeA = currentMillis;
}
if(buttonB != previousStateB && currentMillis - timeB > timer)
{
if(buttonB)
SwitchControlLibrary().PressButtonB();
else
SwitchControlLibrary().ReleaseButtonB();
previousStateB = buttonB;
timeB = currentMillis;
}
if(buttonX != previousStateX && currentMillis - timeX > timer)
{
if(buttonX)
SwitchControlLibrary().PressButtonX();
else
SwitchControlLibrary().ReleaseButtonX();
previousStateX = buttonX;
timeX = currentMillis;
}
if(buttonY != previousStateY && currentMillis - timeY > timer)
{
if(buttonY)
SwitchControlLibrary().PressButtonY();
else
SwitchControlLibrary().ReleaseButtonY();
previousStateY = buttonY;
timeY = currentMillis;
}
if(buttonL != previousStateL && currentMillis - timeL > timer)
{
if(buttonL)
{
SwitchControlLibrary().PressButtonL();
}
else
{
SwitchControlLibrary().ReleaseButtonL();
}
previousStateL = buttonL;
timeL = currentMillis;
}
if(buttonR != previousStateR && currentMillis - timeR > timer)
{
if(buttonR)
SwitchControlLibrary().PressButtonR();
else
SwitchControlLibrary().ReleaseButtonR();
previousStateR = buttonR;
timeR = currentMillis;
}
if(buttonStart != previousStateStart && currentMillis - timeStart > timer)
{
if(buttonStart)
SwitchControlLibrary().PressButtonPlus();
else
SwitchControlLibrary().ReleaseButtonPlus();
previousStateStart = buttonStart;
timeStart = currentMillis;
}
Hat dPad = Hat::CENTER;
if(dpadUp || dpadDown || dpadLeft || dpadRight)
{
if(dpadUp)
{
if(dpadLeft)
{
dPad = Hat::TOP_LEFT;
}
else if(dpadRight)
{
dPad = Hat::TOP_RIGHT;
}
else
{
dPad = Hat::TOP;
}
}
else if(dpadDown)
{
if(dpadLeft)
{
dPad = Hat::BOTTOM_LEFT;
}
else if(dpadRight)
{
dPad = Hat::BOTTOM_RIGHT;
}
else
{
dPad = Hat::BOTTOM;
}
}
else if(dpadRight)
{
dPad = Hat::RIGHT;
}
else if(dpadLeft)
{
dPad = Hat::LEFT;
}
}
if(dPad != previousDPad && currentMillis - timeStart > timer)
{
SwitchControlLibrary().MoveHat((uint8_t) dPad);
previousDPad = dPad;
timeDPad = currentMillis;
}
}