forked from RaccoonFacts/Minecraft-Pickaxe-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinecraftAxeController.ino
More file actions
269 lines (230 loc) · 6.02 KB
/
MinecraftAxeController.ino
File metadata and controls
269 lines (230 loc) · 6.02 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//poorly written code by raccoon facts
//feel free to steal, but keep it spaghetti
//plz sub to my youtube channel
//http://www.youtube.com/raccoonfacts
//k
#include <Mouse.h>
#include <Keyboard.h>
const int xAxis = A1;
const int yAxis = A0;
const int xAxis2 = A2;
const int yAxis2 = A3;
const int joystickButton2 = 9;
const int joystickButton1 = 8;
const int clickSwitch = 7;
const int mouseroll = 10;
const int eButton= 11;
int range= 12;
int responseWait = 5;
int threshold = range / 4;
int center = range / 2;
const unsigned long scrollDelay = 6;
const unsigned long keyboardDelay = 5;
const unsigned long clickDelay = 1;
unsigned long oldTime = 0;
unsigned long oldClickTime = 0;
int led = 12;
int led1 = 13;
int currStateYup;
int prevStateYup;
int currStateYdown;
int prevStateYdown;
int currStateXleft;
int prevStateXleft;
int currStateXright;
int prevStateXright;
void setup()
{
Serial.begin(9600);
pinMode(joystickButton1, INPUT_PULLUP);
pinMode(joystickButton2, INPUT_PULLUP);
pinMode(clickSwitch, INPUT_PULLUP);
pinMode(mouseroll, INPUT);
pinMode(eButton, INPUT );
pinMode(led1, OUTPUT);
pinMode(led, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led, LOW);
Mouse.begin();
Keyboard.begin();
}
void loop()
{
thumbstick();
joystick1();
joystick2();
wasd();
leftClickSwitch();
mouseScroll();
eButt();
}
void leftClickSwitch()
{
int leftClickStatus = digitalRead(clickSwitch);
unsigned long clickTime = millis();
if (leftClickStatus == HIGH)
{
digitalWrite(led, HIGH);
Mouse.release();
}
else
{
digitalWrite(led,LOW);
Mouse.press();
}
}
void thumbstick()
{
unsigned long timeNow = millis();
int xRead = readXAxis(A1);
int yRead = readYAxis(A0);
if (timeNow - oldTime >= keyboardDelay)
{
Mouse.move(xRead, yRead, 0);
oldTime = timeNow;
}
}
void wasd()
{
int sensorValueY = analogRead(yAxis2);
int sensorValueX = analogRead(xAxis2);
{ // Y up )
currStateYup = sensorValueY > 404;
if (currStateYup != prevStateYup)
{
if (currStateYup == (sensorValueY < 50))
{
Keyboard.press('s');
}
else
{
Keyboard.release('s');
}
}
prevStateYup = currStateYup;
}
{ //Y down
currStateYdown = sensorValueY < 594;
if (currStateYdown != prevStateYdown)
{
if (currStateYdown == (sensorValueY > 973))
{
Keyboard.press('w');
}
else
{
Keyboard.release('w');
}
}
prevStateYdown = currStateYdown;
}
{ //X left
currStateXleft = sensorValueX > 408;
if (currStateXleft != prevStateXleft)
{
if (currStateXleft == (sensorValueX < 50))
{
Keyboard.press('d');
}
else
{
Keyboard.release('d');
}
}
prevStateXleft = currStateXleft;
}
{ //X right
currStateXright = sensorValueX < 598;
if (currStateXright != prevStateXright)
{
if (currStateXright == (sensorValueX > 973))
{
Keyboard.press('a');
}
else
{
Keyboard.release('a');
}
}
prevStateXright = currStateXright;
}
}
void eButt()
{
int ekey = digitalRead(eButton);
if (ekey == HIGH)
{
digitalWrite(led1, HIGH);
Keyboard.press('e');
}
else
{
digitalWrite(led1, LOW);
Keyboard.release('e');
}
}
void joystick2()
{
int rightClick = digitalRead(joystickButton2);
if (rightClick == HIGH)
{
digitalWrite(led, LOW);
Keyboard.release(' ');
}
else
{
digitalWrite(led, HIGH);
Keyboard.press(' ');
}
}
void joystick1() //Switched joystick clicks cant be fucked to change name
{
int spaceBar = digitalRead(joystickButton1);
if (spaceBar == HIGH)
{
digitalWrite(led, LOW);
Mouse.release(MOUSE_RIGHT);
}
else
{
digitalWrite(led, HIGH);
Mouse.press(MOUSE_RIGHT);
}
}
void mouseScroll()
{
int scrollyboi = digitalRead(mouseroll);
unsigned long timeNow = millis();
if (scrollyboi == HIGH)
{
digitalWrite(led1, HIGH);
if (timeNow - oldTime >= scrollDelay)
{
Mouse.move(0,0,-1);
oldTime = timeNow;
}
}
else
digitalWrite(led1, LOW);
}
int readXAxis(int thisAxis) {
// reads the initial analog
int reading = analogRead(thisAxis);
//Change range location to invert this mother fucker
reading = map(reading, 0, 1023, range, 0);
int distance = reading - center;
if (abs(distance) < threshold) {
distance = 0;
}
return distance;
}
int readYAxis(int thisAxis) {
int reading = analogRead(thisAxis);
//change range position to 4th if inverting
reading = map(reading, 0, 1023, 0, range);
int distance = reading - center;
if (abs(distance) < threshold) {
distance = 0;
}
return distance;
}