I’m trying to use the Wii classic controller to control my Arduino. At the moment I am only trying to output the name of buttons pressed but I’m getting an error,
“In file included from C:\Users\James\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:5, from ControllerCode.cpp:5:
c:/users/james/arduino-0022/hardware/tools/avr/lib/gcc/…/…/avr/include/string.h:56: error: expected unqualified-id before string constant”
Here is the library I’m using, the Arduino IDE kept throwing error because of it so I’ve change allot, “http://www.arduino.cc/playground/Main/WiiClassicController”.
Any Ideas
Thanks
I think i should also supply the files i have changes as well…
This is my .PDE file for the Arduino,
#include <stdlib.h>
#include <Wire.h>
#include <WiiClassic.h>
WiiClassic wiiClassy = WiiClassic();
void setup() {
Wire.begin();
Serial.begin(9600);
wiiClassy.begin();
wiiClassy.update();
}
void loop() {
delay(100); // 1ms is enough to not overload the wii Classic, 100ms seems to ease the serial terminal a little
wiiClassy.update();
if (wiiClassy.leftShoulderPressed()) {
Serial.print("LS.");
}
if (wiiClassy.rightShoulderPressed()) {
Serial.print("RS.");
}
if (wiiClassy.lzPressed()) {
Serial.print("lz.");
}
if (wiiClassy.rzPressed()) {
Serial.print("rz.");
}
if (wiiClassy.leftDPressed()) {
Serial.print("LD.");
}
if (wiiClassy.rightDPressed()) {
Serial.print("RD.");
}
if (wiiClassy.upDPressed()) {
Serial.print("UD.");
}
if (wiiClassy.downDPressed()) {
Serial.print("DD.");
}
if (wiiClassy.selectPressed()) {
Serial.print("select.");
}
if (wiiClassy.homePressed()) {
Serial.print("home.");
}
if (wiiClassy.startPressed()) {
Serial.print("start.");
}
if (wiiClassy.xPressed()) {
Serial.print("x.");
}
if (wiiClassy.yPressed()) {
Serial.print("y.");
}
if (wiiClassy.aPressed()) {
Serial.print("a.");
}
if (wiiClassy.bPressed()) {
Serial.print("b.");
}
Serial.println();
Serial.print("right shoulder: ");
Serial.println(wiiClassy.rightShouldPressure());
Serial.print(" left shoulder: ");
Serial.println(wiiClassy.leftShouldPressure());
Serial.print(" left stick x: ");
Serial.println(wiiClassy.leftStickX());
Serial.print(" left stick y: ");
Serial.println(wiiClassy.leftStickY());
Serial.print(" right stick x: ");
Serial.println(wiiClassy.rightStickX());
Serial.print(" right stick y: ");
Serial.println(wiiClassy.rightStickY());
Serial.println("---");
//pulse = (int)500+8*wiiClassy.leftStickX();
//updateServo();
}
Here is the .H file
#include <Wire.h>
#ifndef WiiClassic_h
#define WiiClassic_h
class WiiClassic {
private:
uint8_t cnt;
// array to store wiichuck output
uint8_t status[4];
uint8_t averageCounter;
// X,Y,Z
//int accelArray[3][AVERAGE_N];
uint8_t buttons[2];
uint8_t lastButtons[2];
public:
void begin();
void update();
uint8_t getRawStatus();
uint8_t getRawButtons();
bool leftShoulderPressed();
bool rightShoulderPressed();
bool lzPressed();
bool rzPressed();
bool leftDPressed();
bool rightDPressed();
bool upDPressed();
bool downDPressed();
bool selectPressed();
bool homePressed();
bool startPressed();
bool xPressed();
bool yPressed();
bool aPressed();
bool bPressed();
int rightShouldPressure();
int leftShouldPressure();
int leftStickX();
int leftStickY();
int rightStickX();
int rightStickY();
}
#endif
and the .cpp file,
#include <Wire.h>
void WiiClassic::begin()
{
Wire.begin();
cnt = 0;
averageCounter = 0;
Wire.beginTransmission (0x52); // transmit to device 0x52
Wire.send (0x40); // sends memory address
Wire.send (0x00); // sends memory address
Wire.endTransmission (); // stop transmitting
lastButtons[0] = 0xff;
lastButtons[1] = 0xff;
buttons[0] = 0xff;
buttons[1] = 0xff;
update();
}
void WiiClassic::update() {
Wire.requestFrom (0x52, 6); // request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
if (cnt < 4) {
status[cnt] = _nunchuk_decode_byte (Wire.receive());
//_nunchuk_decode_byte ()
} else {
lastButtons[cnt-4] = buttons[cnt-4];
buttons[cnt-4] =_nunchuk_decode_byte (Wire.receive());
}
cnt++;
}
if (cnt > 5) {
_send_zero(); // send the request for next bytes
cnt = 0;
}
}
uint8_t WiiClassic::getRawStatus() {
return status;
}
uint8_t WiiClassic::getRawButtons() {
return buttons;
}
bool WiiClassic::leftShoulderPressed() {
return _PressedRowBit(0,5);
}
bool WiiClassic::rightShoulderPressed() {
return _PressedRowBit(0,1);
}
bool WiiClassic::lzPressed() {
return _PressedRowBit(1,7);
}
bool WiiClassic::rzPressed() {
return _PressedRowBit(1,2);
}
bool WiiClassic::leftDPressed() {
return _PressedRowBit(1,1);
}
bool WiiClassic::rightDPressed() {
return _PressedRowBit(0,7);
}
bool WiiClassic::upDPressed() {
return _PressedRowBit(1,0);
}
bool WiiClassic::downDPressed() {
return _PressedRowBit(0,6);
}
bool WiiClassic::selectPressed() {
return _PressedRowBit(0,4);
}
bool WiiClassic::homePressed() {
return _PressedRowBit(0,3);
}
bool WiiClassic::startPressed() {
return _PressedRowBit(0,2);
}
bool WiiClassic::xPressed() {
return _PressedRowBit(1,3);
}
bool WiiClassic::yPressed() {
return _PressedRowBit(1,5);
}
bool WiiClassic::aPressed() {
return _PressedRowBit(1,4);
}
bool WiiClassic::bPressed() {
return _PressedRowBit(1,6);
}
int WiiClassic::rightShouldPressure() {
return status[3] & 0x1f; //rightmost 5 bits
}
int WiiClassic::leftShouldPressure() {
return ((status[2] & 0x60) >> 2) + ((status[3] & 0xe0) >> 5);
//rightmost 5 bits
}
int WiiClassic::leftStickX() {
return ( (status[0] & 0x3f) );
}
int WiiClassic::leftStickY() {
return ((status[1] & 0x3f));
}
int WiiClassic::rightStickX() {
return ((status[0] & 0xc0) >> 3) + ((status[1] & 0xc0) >> 5) +
((status[2] & 0x80) >> 7);
}
int WiiClassic:: rightStickY() {
return status[2] & 0x1f;
}
private:
bool _PressedRowBit(byte row, byte bit) {
int mask = (1 << bit);
return (!(buttons[row] & mask )) && (lastButtons[row] & mask);
}
int _nunchuk_decode_byte (byte x)
{
int x = (x ^ 0x17) + 0x17;
return x;
}
void _send_zero()
{
Wire.beginTransmission (0x52); // transmit to device 0x52
Wire.send (0x00); // sends one byte
Wire.endTransmission (); // stop transmitting
}
};
#endif