Hey everyone,
While checking out the old "wiichuck demo" code online, I realized that it was based on Arduino 0010, pretty outdated! But I came across a brand new library, released the 20th!
http://www.gabrielbianconi.com/blog/improved-wii-nunchuk-library-for-arduino/
The library was made by Gabriel Bianconi, not me. I tried it out and it works very well from what I've tested so far. It's a great way to set up a Nunchuk quickly, almost "plug and play". Wrote up a quick code to show activity through a row of LED's... haven't got it all commented yet, but it's relatively harmless.
#include <Wire.h>
#include "ArduinoNunchuk.h"
ArduinoNunchuk nunchuk = ArduinoNunchuk();
int xjoystick;
int yjoystick;
int xtilt;
int ytilt;
void setup() {
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(3, OUTPUT);
nunchuk.init();
}
void loop(){
nunchuk.update();
if(nunchuk.cButton == 1 && nunchuk.zButton != 1){
digitalWrite(12, HIGH);
}
else{
digitalWrite(12, LOW);
}
if(nunchuk.zButton == 1 && nunchuk.cButton != 1){
digitalWrite(11, HIGH);
}
else{
digitalWrite(11, LOW);
}
if(nunchuk.cButton == 1 && nunchuk.zButton == 1){
digitalWrite(10, HIGH);
}
else{
digitalWrite(10, LOW);
}
xjoystick = nunchuk.analogX;
xjoystick = constrain(xjoystick, 26, 226);
xjoystick = map(xjoystick, 26, 226, 0, 255);
analogWrite(9, xjoystick);
yjoystick = nunchuk.analogY;
yjoystick = constrain(yjoystick, 26, 226);
yjoystick = map(yjoystick, 26, 226, 0, 255);
analogWrite(6, yjoystick);
xtilt = nunchuk.accelX;
xtilt = constrain(xtilt, 320, 720);
xtilt = map(xtilt, 320, 720, 0, 255);
analogWrite(5, xtilt);
ytilt = nunchuk.accelY;
ytilt = constrain(ytilt, 320, 720);
ytilt = map(ytilt, 320, 720, 0, 255);
analogWrite(3, ytilt);
}
Have fun!
~Alex