Wii Nunchuck Processing for Arduino Uno
in
Android Processing
•
7 months ago
I am new to doing this stuff. I finally figured out you need to have a separate program to "process" the code. I have been trying to do some projects that are in the Arduino cookbook 2nd Edition. I have done simple light projects and the board appears to be good. I purchased an adapter for the Wii Nunchuck. The Arduino program did seem to work but I decided to try the processing code shown on page 130-131. I built the code and had checked it but It doesn't seem to want to Process it.
It stop at: #include <Wire.h>
then there is: #include "nunchuck.h"
It talks about the Nunchuck library on recipe 16.5. What program do I use to build it with?
This is far more complex than I wanted it to be.
Looking on the internet I saw it was talking about a library. I have no clue how to build one or get one. What would I use to even build one. I don't get it!
I would any help I can get!
Here is the code:
/*
* WiichuckSerial
* Uses Nunchuck Library discussed in recipe 16.5
* sends comma-seperated values for data
* Label string separated by commas can be used by receiving 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;
}
It stop at: #include <Wire.h>
then there is: #include "nunchuck.h"
It talks about the Nunchuck library on recipe 16.5. What program do I use to build it with?
This is far more complex than I wanted it to be.
Looking on the internet I saw it was talking about a library. I have no clue how to build one or get one. What would I use to even build one. I don't get it!
I would any help I can get!
Here is the code:
/*
* WiichuckSerial
* Uses Nunchuck Library discussed in recipe 16.5
* sends comma-seperated values for data
* Label string separated by commas can be used by receiving 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