Wiichuck/Arduino controlled LEDs

I got an Arduino a few weeks ago and I’ve been playing with it pretty obsessively since then.   Since the Wii Nunchuck controllers use an I2C serial it’s super easy to connect one to the Arduino.  Here’s a nice tutorial I used to connect the Nunchuck to the Arduino.  I got my WiiChuck adapter from FunGizmos for $4.  It comes unsoldered but it’s only four pins, so no big deal.  I should mention that I’m using Tim Hirzel’s version of the WiiChuck library which has some nice improvements to the rotation data from the Nunchuck; although in this demo I’m not using the accelerometer data.

I’ve also been working for a while on a music visualization project using a bunch of LEDs.  Initially I was connecting the LEDs directly to the PWM outputs on the Arduino.  But since there are only six of them I quickly realized I needed some way to control many more pins.  I found a nice library for the TLC5940 16-channel LED driver from Texas Instruments.  TI offers free samples for many of their components, so I was able to get a couple TLC5940’s for free (no shipping even)!  The library includes all the instructions for how to wire up the device so it was really easy to get that up and going.  The library also offers features specifically for controlling servos which I will have to check out at some point.

The default demo included with the library is a Knight Rider style animation of the LEDs.  I modified that demo to use the joystick input from the nunchuck to move the active LED around.  The input value ranges from -100 to 100 for the joystick which I square and normalize down to get nicer analogish movement (i.e the ability to just slightly move the point or move it very quickly).  I’m using two daisy-chained TLCs, which is almost as easy as using one.  You just take one of the outputs from the first and plug it into the second.  All the rest of the connections can be shared (each does require its own 2k resistor).  One last thing you have to do is adjust the NUM_TLCS variable in tlc_config.h.


#include <Tlc5940.h>
#include <tlc_animations.h>
#include <tlc_config.h>
#include <tlc_fades.h>
#include <tlc_progmem_utils.h>
#include <tlc_servos.h>
#include <math.h>
#include "Wire.h"
#include "WiiChuck.h"

WiiChuck chuck = WiiChuck();
double xJoy;
double position = 15;

void setup() {

void loop() {
xJoy = chuck.readJoyX();
//We want to move only if the user has really moved the joystick,
//otherwise the LEDs flicker back and forth.
if (abs(xJoy) > 10) {
if (xJoy < 0) position -= pow(xJoy,2)/5000.0;
if (xJoy > 0) position += pow(xJoy,2)/5000.0;
if (position < 1) position = 1;
if (position > 30) position = 30;
Tlc.set((int)position-2, 100);
Tlc.set((int)position-1, 1000);
Tlc.set((int)position, 4095);
Tlc.set((int)position+1, 1000);
Tlc.set((int)position+2, 100);


0 Responses to “Wiichuck/Arduino controlled LEDs”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: