January 13, 2010

Post date: Jan 13, 2010 5:8:48 PM

We modified our program so the serial monitor only registers when there is important data given so it isn't constantly displaying insignificant data. Now it will only show when the nunchuck is being put to use. Today we will modify the code to work better with our setup.

The serial monitor will only show numbers above 190.

Here is the code we are currently using:

#include <Wire.h>

#include "nunchuck_funcs.h"

int an[] = {11,12,13,11,12,13,10,13,10,12,10,11,10,9,9,11,12,9,8,11,8,10,8,9,8,7,9,7,10,7,7,11,12,7,13,7};

int ca[] = {12,11,11,13,13,12,13,10,12,10,11,10,9,10,11,9,9,12,11,8,10,8,9,8,7,8,7,9,7,10,11,7,7,12,7,13};

int loop_cnt=0;

int t = 2500;

byte accx,accy,zbut,cbut;

int ledPin = 13;

int x=0;

int y = 0;

void setup()

{

for (int pin =7; pin<=13; pin++)

{

pinMode(pin,INPUT);

}

Serial.begin(19200);

nunchuck_setpowerpins();

nunchuck_init(); // send the initilization handshake

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();

x = nunchuck_accelx();

x= map(x,0,255,0,35);

delayMicroseconds(t);

pinMode (an[x], OUTPUT);

pinMode (ca[x], OUTPUT);

digitalWrite(an[x], HIGH);

digitalWrite(ca[x], LOW);

delayMicroseconds(t);

digitalWrite(an[x], LOW);

digitalWrite(ca[x], LOW);

delayMicroseconds(t);

pinMode (an[x], INPUT);

pinMode (ca[x], INPUT);

if (accx > 190)

{

Serial.print("accx: "); Serial.print((byte)accx,DEC);

Serial.print("time: "); Serial.println((long)millis(), DEC);

}

}

loop_cnt++;

delay(1);

}