Wii Nunchuck used with Arduino Uno
in
Integration and Hardware
•
7 months ago
This is a repost because so far I have not received an answer.
I decided to try the Processing sketch on page 131-132 of the Recipe book. When I try to run it it stops at #include <Wire.h> At the bottom it says unexpected character: 'i'
I was seeing some posts about a library. If that is true I have no clue how to get it, build it or whatever. I messed around with trying something in Wordpad. Well! Nothing I tried worked. I guess I didn't think this was going to be this difficult. I want to try to get this going as soon as I can so that I can go on to other programs. I think I need to sol it.
Here is the code:
/*
* WiichuckSerial
* Uses Nunchuck Library discussed in recipe 16.5
* sends comma-seperated values for data
* Label string seperated by commas can be used by recieving program
* to identify fields
*/
#include <Wire.h>
#include "Nunchuck.h"
// values to add to the sensor to get zero reading when centered
int offsetX, offsetY, offsetZ;
#include <Wire.h>
#include "Nunchuck.h"
void setup()
{
Serial.begin(57600);
nunchuckSetPowerpins()
nunchuckInit(); // send the intitialization handshake
nunchuckRead; // ignore the first time
delay(50);
}
void loop()
{
nunchuckRead();
dalay(6);
nunchuck_get_data();
boolean btnC = nunchuckGetValue(wii_btnC);
boolean btnC = nunchuckGetValue(wii_btnZ);
if(btnC) {
offsetX = 127 nunchuckGetValue(wii_accelX);
offsetX = 127 nunchuckGetValue(wii_accelY);
}
serial.print("Data,");
printAccel(nunchuckGetValue(wii_accelX),offsetX;
printAccel(nunchuckGetValue(wii_accelY),offsetY;
printButton(nunchuckGetValue(wii_btnZ));
Serial.println();
}
void printAccel(int value,int offset)
{
serial.print(adjReading(value, 127-50, 127+50, offset));
}
void printJoy(int value)
{
Serial.print(adjReading(value,0, 255, 0));
Serial.print(",")
}
void printButton(int value)
{
if( value != 0)
value = 127;
Serial.print(value,DEC);
Serial.print(",");
}
int addReading( int value, int min, int max, int offset)
{
value = constrain(value + offset, min, max);
value = map(value, min, max, -127, 127);
return value;
}
I decided to try the Processing sketch on page 131-132 of the Recipe book. When I try to run it it stops at #include <Wire.h> At the bottom it says unexpected character: 'i'
I was seeing some posts about a library. If that is true I have no clue how to get it, build it or whatever. I messed around with trying something in Wordpad. Well! Nothing I tried worked. I guess I didn't think this was going to be this difficult. I want to try to get this going as soon as I can so that I can go on to other programs. I think I need to sol it.
Here is the code:
/*
* WiichuckSerial
* Uses Nunchuck Library discussed in recipe 16.5
* sends comma-seperated values for data
* Label string seperated by commas can be used by recieving program
* to identify fields
*/
#include <Wire.h>
#include "Nunchuck.h"
// values to add to the sensor to get zero reading when centered
int offsetX, offsetY, offsetZ;
#include <Wire.h>
#include "Nunchuck.h"
void setup()
{
Serial.begin(57600);
nunchuckSetPowerpins()
nunchuckInit(); // send the intitialization handshake
nunchuckRead; // ignore the first time
delay(50);
}
void loop()
{
nunchuckRead();
dalay(6);
nunchuck_get_data();
boolean btnC = nunchuckGetValue(wii_btnC);
boolean btnC = nunchuckGetValue(wii_btnZ);
if(btnC) {
offsetX = 127 nunchuckGetValue(wii_accelX);
offsetX = 127 nunchuckGetValue(wii_accelY);
}
serial.print("Data,");
printAccel(nunchuckGetValue(wii_accelX),offsetX;
printAccel(nunchuckGetValue(wii_accelY),offsetY;
printButton(nunchuckGetValue(wii_btnZ));
Serial.println();
}
void printAccel(int value,int offset)
{
serial.print(adjReading(value, 127-50, 127+50, offset));
}
void printJoy(int value)
{
Serial.print(adjReading(value,0, 255, 0));
Serial.print(",")
}
void printButton(int value)
{
if( value != 0)
value = 127;
Serial.print(value,DEC);
Serial.print(",");
}
int addReading( int value, int min, int max, int offset)
{
value = constrain(value + offset, min, max);
value = map(value, min, max, -127, 127);
return value;
}
1