As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Tuesday, June 11, 2013

Trash Talk | WiiChuck Motion Sensing | Sam + Willie

When envisioning the ideal Trash Talk interaction, Willie and I thought that it would be pretty sweet if the recycling can could know if someone's "shot" hit the outside and didn't go in; a "brick" if you will. After a little bit of research, it turns out that the WiiChuck from a Nintendo Wii can be used with Arduino to detect motion! And someone had already designed an adapter and written a library for it!!

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