mirror of https://github.com/falsovsky/arduino.git
Optimizado pelo phantoxe e theorem
This commit is contained in:
parent
e8bd762fe8
commit
5b90df5b7d
|
@ -40,11 +40,7 @@ void setup() {
|
||||||
digitalWrite(latch,HIGH);
|
digitalWrite(latch,HIGH);
|
||||||
digitalWrite(clock,HIGH);
|
digitalWrite(clock,HIGH);
|
||||||
|
|
||||||
// Set joystick initial state
|
|
||||||
joySt.xAxis = 127;
|
|
||||||
joySt.yAxis = 127;
|
|
||||||
joySt.zAxis = 127;
|
joySt.zAxis = 127;
|
||||||
joySt.buttons = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* THIS READS DATA FROM THE CONTROLLER */
|
/* THIS READS DATA FROM THE CONTROLLER */
|
||||||
|
@ -73,7 +69,6 @@ word controllerRead() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Clock Cycle Button Reported
|
Clock Cycle Button Reported
|
||||||
=========== ===============
|
=========== ===============
|
||||||
|
@ -97,125 +92,36 @@ void loop() {
|
||||||
|
|
||||||
word controller_data = controllerRead();
|
word controller_data = controllerRead();
|
||||||
|
|
||||||
// B - BIT 16
|
joySt.buttons = 0;
|
||||||
if (!btn_b && bitRead(controller_data, 15) == 0) {
|
|
||||||
btn_b = true;
|
|
||||||
joySt.buttons = joySt.buttons | 1;
|
|
||||||
}
|
|
||||||
if (btn_b && bitRead(controller_data, 15) == 1) {
|
|
||||||
joySt.buttons = joySt.buttons & 254;
|
|
||||||
btn_b = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Y - BIT 15
|
joySt.buttons |= (!bitRead(controller_data, 15) << 0);
|
||||||
if (!btn_y && bitRead(controller_data, 14) == 0) {
|
joySt.buttons |= (!bitRead(controller_data, 14) << 1);
|
||||||
btn_y = true;
|
joySt.buttons |= (!bitRead(controller_data, 7) << 2);
|
||||||
joySt.buttons = joySt.buttons | 2;
|
joySt.buttons |= (!bitRead(controller_data, 6) << 3);
|
||||||
}
|
joySt.buttons |= (!bitRead(controller_data, 5) << 4);
|
||||||
if (btn_y && bitRead(controller_data, 14) == 1) {
|
joySt.buttons |= (!bitRead(controller_data, 4) << 5);
|
||||||
btn_y = false;
|
joySt.buttons |= (!bitRead(controller_data, 13) << 6);
|
||||||
joySt.buttons = joySt.buttons & 253;
|
joySt.buttons |= (!bitRead(controller_data, 12) << 7);
|
||||||
}
|
|
||||||
|
|
||||||
// SELECT - BIT 14
|
|
||||||
if (!btn_select && bitRead(controller_data, 13) == 0) {
|
|
||||||
btn_select = true;
|
|
||||||
joySt.buttons = joySt.buttons | 64;
|
|
||||||
}
|
|
||||||
if (btn_select && bitRead(controller_data, 13) == 1) {
|
|
||||||
btn_select = false;
|
|
||||||
joySt.buttons = joySt.buttons & 191;
|
|
||||||
}
|
|
||||||
|
|
||||||
// START - BIT 13
|
joySt.xAxis = 127;
|
||||||
if (!btn_start && bitRead(controller_data, 12) == 0) {
|
joySt.yAxis = 127;
|
||||||
btn_start = true;
|
|
||||||
joySt.buttons = joySt.buttons | 128;
|
|
||||||
}
|
|
||||||
if (btn_start && bitRead(controller_data, 12) == 1) {
|
|
||||||
btn_start = false;
|
|
||||||
joySt.buttons = joySt.buttons & 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
// UP - BIT 12
|
// UP - BIT 12
|
||||||
if (!btn_up && bitRead(controller_data, 11) == 0) {
|
if (!bitRead(controller_data, 11))
|
||||||
btn_up = true;
|
|
||||||
joySt.yAxis = 0;
|
joySt.yAxis = 0;
|
||||||
}
|
|
||||||
if (btn_up && bitRead(controller_data, 11) == 1) {
|
|
||||||
btn_up = false;
|
|
||||||
joySt.yAxis = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
// DOWN - BIT 11
|
// DOWN - BIT 11
|
||||||
if (!btn_down && bitRead(controller_data, 10) == 0) {
|
if (!bitRead(controller_data, 10))
|
||||||
btn_down = true;
|
|
||||||
joySt.yAxis = 255;
|
joySt.yAxis = 255;
|
||||||
}
|
|
||||||
if (btn_down && bitRead(controller_data, 10) == 1) {
|
|
||||||
btn_down = false;
|
|
||||||
joySt.yAxis = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
// LEFT - BIT 10
|
// LEFT - BIT 10
|
||||||
if (!btn_left && bitRead(controller_data, 9) == 0) {
|
if (!bitRead(controller_data, 9))
|
||||||
btn_left = true;
|
|
||||||
joySt.xAxis = 0;
|
joySt.xAxis = 0;
|
||||||
}
|
|
||||||
if (btn_left && bitRead(controller_data, 9) == 1) {
|
|
||||||
btn_left = false;
|
|
||||||
joySt.xAxis = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
// RIGHT - BIT 9
|
// RIGHT - BIT 9
|
||||||
if (!btn_right && bitRead(controller_data, 8) == 0) {
|
if (!bitRead(controller_data, 8))
|
||||||
btn_right = true;
|
|
||||||
joySt.xAxis = 255;
|
joySt.xAxis = 255;
|
||||||
}
|
|
||||||
if (btn_right && bitRead(controller_data, 8) == 1) {
|
|
||||||
btn_right = false;
|
|
||||||
joySt.xAxis = 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A - BIT 8
|
|
||||||
if (!btn_a && bitRead(controller_data, 7) == 0) {
|
|
||||||
btn_a = true;
|
|
||||||
joySt.buttons = joySt.buttons | 4;
|
|
||||||
}
|
|
||||||
if (btn_a && bitRead(controller_data, 7) == 1) {
|
|
||||||
btn_a = false;
|
|
||||||
joySt.buttons = joySt.buttons & 251;
|
|
||||||
}
|
|
||||||
|
|
||||||
// X - BIT 7
|
|
||||||
if (!btn_x && bitRead(controller_data, 6) == 0) {
|
|
||||||
btn_x = true;
|
|
||||||
joySt.buttons = joySt.buttons | 8;
|
|
||||||
}
|
|
||||||
if (btn_x && bitRead(controller_data, 6) == 1) {
|
|
||||||
btn_x = false;
|
|
||||||
joySt.buttons = joySt.buttons & 247;
|
|
||||||
}
|
|
||||||
|
|
||||||
// L - BIT 6
|
|
||||||
if (!btn_l && bitRead(controller_data, 5) == 0) {
|
|
||||||
btn_l = true;
|
|
||||||
joySt.buttons = joySt.buttons | 16;
|
|
||||||
}
|
|
||||||
if (btn_l && bitRead(controller_data, 5) == 1) {
|
|
||||||
btn_l = false;
|
|
||||||
joySt.buttons = joySt.buttons & 239;
|
|
||||||
}
|
|
||||||
|
|
||||||
// R - BIT 5
|
|
||||||
if (!btn_r && bitRead(controller_data, 4) == 0) {
|
|
||||||
btn_r = true;
|
|
||||||
joySt.buttons = joySt.buttons | 32;
|
|
||||||
}
|
|
||||||
if (btn_r && bitRead(controller_data, 4) == 1) {
|
|
||||||
btn_r = false;
|
|
||||||
joySt.buttons = joySt.buttons & 223;
|
|
||||||
}
|
|
||||||
|
|
||||||
Joystick.setState(&joySt);
|
Joystick.setState(&joySt);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue