Last active
October 11, 2019 17:32
-
-
Save pol8139/fb16958e856889fa5b1c050c464cd6d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiiChuck.h> | |
| #define BUF_SIZE 6 | |
| Accessory nunchuck1; | |
| uint8_t buf[BUF_SIZE]; | |
| //char buf00[8] = {}; | |
| //char buf01[8] = {}; | |
| //char buf02[8] = {}; | |
| //char buf03[8] = {}; | |
| //char buf04[8] = {}; | |
| //char buf05[8] = {}; | |
| bool home_button; | |
| void setup() { | |
| Serial2.begin(115200); | |
| nunchuck1.begin(); | |
| if (nunchuck1.type == Unknown) { | |
| /** If the device isn't auto-detected, set the type explicatly | |
| * NUNCHUCK, | |
| WIICLASSIC, | |
| GuitarHeroController, | |
| GuitarHeroWorldTourDrums, | |
| DrumController, | |
| DrawsomeTablet, | |
| Turntable | |
| */ | |
| nunchuck1.type = WIICLASSIC; | |
| } | |
| } | |
| void loop() { | |
| if(Serial2.available() > 0) { | |
| uint8_t read_data; | |
| read_data = Serial2.read(); | |
| if(read_data == 'e') { //erase | |
| for(int i = 0; i < BUF_SIZE; i++) { | |
| buf[i] = 0x00; | |
| } | |
| } else if(read_data == 'g') { //get | |
| nunchuck1.readData(); // Read inputs and update maps | |
| home_button = nunchuck1.values[15] >> 7; | |
| buf[0] = (nunchuck1.values[18] & 0x80) | (nunchuck1.values[10] & 0x40) | ((!home_button && nunchuck1.values[17]) << 5) | ((!home_button && nunchuck1.values[11]) << 4) | (nunchuck1.values[8] & 0x08) | (nunchuck1.values[12] & 0x04) | (nunchuck1.values[13] & 0x02) | (nunchuck1.values[9] & 0x01); | |
| buf[1] = ((nunchuck1.values[7] & 0x01) << 7) | (!!!nunchuck1.values[7] << 6) | ((home_button && nunchuck1.values[11]) << 5) | ((home_button && nunchuck1.values[17]) << 4) | ((home_button && (nunchuck1.values[14] & 0x01)) << 3) | ((home_button && !nunchuck1.values[14]) << 2) | ((!home_button && (nunchuck1.values[14] & 0x01)) << 1) | ((!home_button && !nunchuck1.values[14]) << 0); | |
| buf[2] = nunchuck1.values[2] & 0xFC | ((nunchuck1.values[6] & 0x01) << 1) | (!!!nunchuck1.values[6] << 0); | |
| buf[3] = nunchuck1.values[3] & 0xFC; | |
| buf[4] = nunchuck1.values[0]; | |
| buf[5] = nunchuck1.values[1]; | |
| // sprintf(buf00, "%X", buf[0]); | |
| // sprintf(buf01, "%X", buf[1]); | |
| // sprintf(buf02, "%X", buf[2]); | |
| // sprintf(buf03, "%X", buf[3]); | |
| // sprintf(buf04, "%X", buf[4]); | |
| // sprintf(buf05, "%X", buf[5]); | |
| // Serial.println(buf00); | |
| // Serial.println(buf01); | |
| // Serial.println(buf02); | |
| // Serial.println(buf03); | |
| // Serial.println(buf04); | |
| // Serial.println(buf05); | |
| } else if(read_data == '0') { | |
| Serial2.write(buf[0]); | |
| } else if(read_data == '1') { | |
| Serial2.write(buf[1]); | |
| } else if(read_data == '2') { | |
| Serial2.write(buf[2]); | |
| } else if(read_data == '3') { | |
| Serial2.write(buf[3]); | |
| } else if(read_data == '4') { | |
| Serial2.write(buf[4]); | |
| } else if(read_data == '5') { | |
| Serial2.write(buf[5]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment