need help with wiichuck controlling leds

ok ive been searching for a bit and cant really find what i need maybe i am im just not interpreting it right, anyway i have my chuck setup the way i like it where it shows the x and y axis along with the 2 buttons where it works good but now im stuck i have a way that i want to control the lights with the c button where it switches between modes such a a rainbow effect along with a police style flasher and one more where the chuck controls the colors at least the red and blue (red x and blue y) im a little stumped im not very good with this coding ive had this less then a week so if anyone can point me in the right direction or give me a little help it would be great thanx for reading and this is a wonderfuly fun toy lol

add pictures, schematics, code and more than a paragraph to describe what it is your doing

where it shows the x and y axis along with the 2 buttons where it works good

where does it show where its showing?

i have a way that i want to control the lights

what lights?

i cant take pictures right now but the code is here

 * WiiChuckDemo -- 
 * 2008 Tod E. Kurt,

#include <Wire.h>
#include "nunchuck_funcs.h"

int loop_cnt=0;

byte accx,accy,zbut,cbut;
int ledPin = 13;

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


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

that is the code to read it the output is

accx: 111 accy: 222 zbut: 0 cbut: 1

if i remember right the main thing id like to do is learn how to take the code its reading from the chuck and make it control the lights the lights i have are standard rgb led lights that are common ground lights

what else can i tell you i will come back with more i need probably but right now i don’t know what else to say other then thank you for the response

thanks that helps a bit more to narrow down what your trying to do, and dont feel bad everyone gets the smack now and again, even me ... often me ...

now onwards, how many LED's are you trying to control, you can take that number and effectively multiply it by 3 cause in a RGB led there is 3 LED dies in one epoxy blob

then there is a depth of color to think about, how smooth do you want your rainbow effect, keeping in mind your eyes naturally blend stuff, you dont need millions or really thousands of colors, but if it's more than BAM red BAM purple BAM blue etc, that will effect how you code it (ie hard coded values vs a nice sinusoidal wave) and a small handful of other considerations

but for now, just trying to get what you see in your head onto the forum, then everyone can jump in and get you sorted out, while you learn a bunch of fun and exciting things!

yeah thank you this seems like a great forum a lot of nice people but anyway my main goal right now is to learn how to switch modes with a button push and maybe since i have a rainbow code i like anyway id like to impliment it and be able to change the speed based on the x or y axis position my rbg rainbow code is this

// Rainbow color changing RGB leds example
// I am using common cathode RGB leds
int PIN_RED = 9;
int PIN_GREEN = 11;
int PIN_BLUE = 10;
int counter = 0;

// Number of colors used for animating, higher = smoother and slower animation)
int numColors = 1220;

  // The combination of numColors and animationDelay determines the
  // animation speed, I recommend a higher number of colors if you want
  // to slow down the animation. Higher number of colors = smoother color changing.
int animationDelay = 5; // number milliseconds before RGB LED changes to next color

void setup() {
  pinMode(PIN_RED, OUTPUT);
  pinMode(PIN_BLUE, OUTPUT);

void loop() {
  // This part takes care of displaying the
  // color changing in reverse by counting backwards if counter
  // is above the number of available colors  
  float colorNumber = counter > numColors ? counter - numColors: counter;
  // Play with the saturation and brightness values
  // to see what they do
  float saturation = 1; // Between 0 and 1 (0 = gray, 1 = full color)
  float brightness = 1; // Between 0 and 1 (0 = dark, 1 is full brightness)
  float hue = (colorNumber / float(numColors)) * 360; // Number between 0 and 360
  long color = HSBtoRGB(hue, saturation, brightness);
  // Get the red, blue and green parts from generated color
  int red = color >> 16 & 255;
  int green = color >> 8 & 255;
  int blue = color & 255;

  setColor(red, green, blue);
  // Counter can never be greater then 2 times the number of available colors
  // the colorNumber = line above takes care of counting backwards (nicely looping animation)
  // when counter is larger then the number of available colors
  counter = (counter + 1) % (numColors * 2);
  // If you uncomment this line the color changing starts from the
  // beginning when it reaches the end (animation only plays forward)
  // counter = (counter + 1) % (numColors);


void setColor (unsigned char red, unsigned char green, unsigned char blue)
    analogWrite(PIN_RED, red);
    analogWrite(PIN_GREEN, green);
    analogWrite(PIN_BLUE, blue);

long HSBtoRGB(float _hue, float _sat, float _brightness) {
    float red = 0.0;
    float green = 0.0;
    float blue = 0.0;
    if (_sat == 0.0) {
        red = _brightness;
        green = _brightness;
        blue = _brightness;
    } else {
        if (_hue == 360.0) {
            _hue = 0;

        int slice = _hue / 60.0;
        float hue_frac = (_hue / 60.0) - slice;

        float aa = _brightness * (1.0 - _sat);
        float bb = _brightness * (1.0 - _sat * hue_frac);
        float cc = _brightness * (1.0 - _sat * (1.0 - hue_frac));
        switch(slice) {
            case 0:
                red = _brightness;
                green = cc;
                blue = aa;
            case 1:
                red = bb;
                green = _brightness;
                blue = aa;
            case 2:
                red = aa;
                green = _brightness;
                blue = cc;
            case 3:
                red = aa;
                green = bb;
                blue = _brightness;
            case 4:
                red = cc;
                green = aa;
                blue = _brightness;
            case 5:
                red = _brightness;
                green = aa;
                blue = bb;
                red = 0.0;
                green = 0.0;
                blue = 0.0;

    long ired = red * 255.0;
    long igreen = green * 255.0;
    long iblue = blue * 255.0;
    return long((ired << 16) | (igreen << 8) | (iblue));

i really like this code because it is bright and works great i edited it a little for my liking but i like it but after that id like to have multipule modes where i can switch them with the buttons if that makes sence