die Zeile finde ich nicht...
Code:/* * Nunchuk auslesen * * funktioniert mit original Nunchuck * UND mit Wirelesse Nunchuck * * Pinbelegung: * 3.3V (Kabel rot) * GND (Kabel weiß) * A4 (Kabel grün) * A5 (Kabel gelb) */ #include <Wire.h> const int dataLength = 6; // numer ob bytes to request static byte rawData[dataLength]; // array to store nunchuck data // construct to create an enumerated list of the sonsor values returned from the nunchuck enum nunchuckItems { joyX, joyY, accelX, accelY, accelZ, btnZ, btnC }; void setup() { Serial.begin(57600); delay(500); Serial.println("Labels,Xjoy,Yjoy,Xaccel,Yaccel,Zaccel,Z-btn,C-btn,"); delay(500); nunchuckInit(); } void loop() { if (nunchuckRead() == true) { Serial.print("Data,"); // Data-Header Serial.print(getValue(joyX), DEC); Serial.write(","); Serial.print(getValue(joyY), DEC); Serial.write(","); Serial.print(getValue(accelX), DEC); Serial.write(","); Serial.print(getValue(accelY), DEC); Serial.write(","); Serial.print(getValue(accelZ), DEC); Serial.write(","); Serial.print(getValue(btnZ), DEC); Serial.write(","); Serial.print(getValue(btnC), DEC); // Serial.write(",0"); // Serial.write("\n"); Serial.println(); } delay(20); // time between redraws } void nunchuckInit() { Wire.begin(); // join I2C bus as master Wire.beginTransmission(0x52); // transmit to device 0x52 Wire.write((byte)0xF0); // send memory adress Wire.write((byte)0x55); // send a zero if (Wire.endTransmission() == 0) { Wire.beginTransmission(0x52); // transmit to device 0x52 Wire.write((byte)0xA5); // send memory adress Wire.write((byte)0x00); } // stop transmission } // send a request for data to the nunchuck static void nunchuckRequest() { Wire.beginTransmission(0x52); // transmit to device 0x52 Wire.write((byte)0x00); // send one byte Wire.endTransmission(); // stop transmission } // receive data back from the nunchuck, // returns true if read successful, else false boolean nunchuckRead() { int cnt=0; Wire.requestFrom (0x52, dataLength); // request data from nunchuck while (Wire.available ()) { rawData[cnt] = Wire.read(); cnt++; } nunchuckRequest(); // send request for next dat payload if (cnt >= dataLength) return true; // success if all 6 bytes received else return false; // failure } // encode data to format that most wiimote drivers accept // static char nunchuckDecode (byte x) { // return (x ^ 0x17) + 0x17; // return x; // } int getValue(int item) { if (item <= accelZ) return (int)rawData[item]; else if (item == btnZ) return bitRead(rawData[5], 0) ? 0: 100; else if (item == btnC) return bitRead(rawData[5], 1) ? 0: 100; }







Zitieren

Lesezeichen