We were able to get it up and running with both our Arduino UNO and Arduino MEGA, and blink an LED when it detected motion. Ultimately, combining the jiggle and the blink proved to be beyond the scope of my code knowledge, but here's our code for a simple jiggle + blink:
/*
* WiiChuckDemo --
*
* 2008 Tod E. Kurt, http://thingm.com/
*
*/
#include <Wire.h>
#include "nunchuck_funcs.h"
int loop_cnt=0;
int lastAccx = 0;
byte accx,accy,zbut,cbut;
int ledPin = A14;
void setup()
{
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
pinMode(ledPin, OUTPUT); //makes led on pin 13 an output pin
Serial.print("WiiChuckDemo ready\n");
}
void loop()
{
if( loop_cnt > 100 ) { // every 100 msecs get new data
loop_cnt = 0;
nunchuck_get_data();
accx = nunchuck_accelx(); // ranges from approx 70 - 182
//accy = nunchuck_accely(); // ranges from approx 65 - 173
//zbut = nunchuck_zbutton();
//cbut = nunchuck_cbutton();
Serial.print("accx: "); Serial.print((byte)accx,DEC);
//Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
//Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
//Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);
}
if(accx != lastAccx) {
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
}
lastAccx = accx;
loop_cnt++;
delay(1);
}
No comments:
Post a Comment