I am trying to setup a LPD8806 RGB light strip to run different sequences at differences I am using a sketch that I found for running a piezo speaker to sound at different distances and different hrz along with the advanced led belt kit.

I have been abe to get both of them working indepently but have not been able to combine them.

#if defined(USB_SERIAL) || defined(USB_SERIAL_ADAFRUIT)// this is for teensyduino supportint dataPin = 2;int clockPin = 1;#else // these are the pins we use for the LED belt kit using// the Leonardo pinoutsint dataPin = 16;int clockPin = 15;#endif

// Declare the number of pixels in strand; 32 = 32 pixels in a row. The// LED strips have 32 LEDs per meter, but you can extend or cut the strip.const int numPixels = 32;// 'const' makes subsequent array declarations possible, otherwise there// would be a pile of malloc() calls later.

// Instantiate LED strip; arguments are the total number of pixels in strip,// the data pin number and clock pin number:LPD8806 strip = LPD8806(numPixels, dataPin, clockPin);

// You can also use hardware SPI for ultra-fast writes by omitting the data// and clock pin arguments. This is faster, but the data and clock are then// fixed to very specific pin numbers: on Arduino 168/328, data = pin 11,// clock = pin 13. On Mega, data = pin 51, clock = pin 52.//LPD8806 strip = LPD8806(numPixels);

// Principle of operation: at any given time, the LEDs depict an image or// animation effect (referred to as the "back" image throughout this code).// Periodically, a transition to a new image or animation effect (referred// to as the "front" image) occurs. During this transition, a third buffer// (the "alpha channel") determines how the front and back images are// combined; it represents the opacity of the front image. When the// transition completes, the "front" then becomes the "back," a new front// is chosen, and the process repeats.byte imgData[2][numPixels * 3], // Data for 2 strips worth of imagery alphaMask[numPixels], // Alpha channel for compositing images backImgIdx = 0, // Index of 'back' image (always 0 or 1) fxIdx[3]; // Effect # for back & front images + alphaint fxVars[3][50], // Effect instance variables (explained later) tCounter = -1, // Countdown to next transition transitionTime; // Duration (in frames) of current transition

// List of image effect and alpha channel rendering functions; the code for// each of these appears later in this file. Just a few to start with...// simply append new ones to the appropriate list here:void (*renderEffect[])(byte) = { renderEffect00, renderEffect01, renderEffect02, renderEffect03 },(*renderAlpha[])(void) = { renderAlpha00, renderAlpha01, renderAlpha02 };

// Start up the LED strip. Note that strip.show() is NOT called here -- // the callback function will be invoked immediately when attached, and // the first thing the calback does is update the strip. strip.begin();

// Timer1 is used so the strip will update at a known fixed frame rate. // Each effect rendering function varies in processing complexity, so // the timer allows smooth transitions between effects (otherwise the // effects and transitions would jump around in speed...not attractive). Timer1.initialize(); Timer1.attachInterrupt(callback, 1000000 / 60); // 60 frames/second}

// First parameter is the number of LEDs in the strand. The LED strips// are 32 LEDs per meter but you can extend or cut the strip. Next two// parameters are SPI data and clock pins:LPD8806 strip = LPD8806(32, dataPin, clockPin);

for (j=0; j < 384 * 1; j++) { // 5 cycles of all 384 colors in the wheel for (i=0; i < strip.numPixels(); i++) { // tricky math! we use each pixel as a fraction of the full 384-color wheel // (thats the i / strip.numPixels() part) // Then add in j which makes the colors go around per pixel // the % 384 is to make the wheel cycle around strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) ); } strip.show(); // write all the pixels out

}}

/* Helper functions */

//Input a value 0 to 384 to get a color value.//The colours are a transition r - g -b - back to r

The issue I am having now is that I want the strip to not complete the sequence if a new distance is detected. Currently the new led sequence will run to the end then start the other I am trying to get the strip to stop what its running where ever it maybe when a new distance is detected and run that led sequence instead.

You need to declare a boolean variable and set it to "true" whenever the distance changes significantly. Then you need to test that variable inside the 'for' loops of your rainbowcycle and colorwipe functions. If it is "true", the function should set it to "false"and then return immediately.

// First parameter is the number of LEDs in the strand. The LED strips// are 32 LEDs per meter but you can extend or cut the strip. Next two// parameters are SPI data and clock pins:LPD8806 strip = LPD8806(32, dataPin, clockPin);

for (j=0; j < 384 * 1; j++) { // 5 cycles of all 384 colors in the wheel for (i=0; i < strip.numPixels(); i++) { // tricky math! we use each pixel as a fraction of the full 384-color wheel // (thats the i / strip.numPixels() part) // Then add in j which makes the colors go around per pixel // the % 384 is to make the wheel cycle around strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) ); } strip.show(); // write all the pixels out

}}

/* Helper functions */

//Input a value 0 to 384 to get a color value.//The colours are a transition r - g -b - back to r

Now I am getting some weird overlap of the sequence where they are combining with each other and then at some spots and then when I hit the rainbow sequence it will run the sequence then run single version of the other

so bascially the closest sequence basically runs all three in a loop the middle one runs the 2 sequences in a loop but the furthest one out is stable

I think that have something to do with the inequalities that are establishing the distances

// First parameter is the number of LEDs in the strand. The LED strips// are 32 LEDs per meter but you can extend or cut the strip. Next two// parameters are SPI data and clock pins:LPD8806 strip = LPD8806(32, dataPin, clockPin);

for (j=0; j < 384 * 1; j++) { // 5 cycles of all 384 colors in the wheel for (i=0; i < strip.numPixels(); i++) { // tricky math! we use each pixel as a fraction of the full 384-color wheel // (thats the i / strip.numPixels() part) // Then add in j which makes the colors go around per pixel // the % 384 is to make the wheel cycle around strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) ); } strip.show(); // write all the pixels out

if (distanceChanged(3)) return;

}}

/* Helper functions */

//Input a value 0 to 384 to get a color value.//The colours are a transition r - g -b - back to r

so bascially the closest sequence basically runs all three in a loop the middle one runs the 2 sequences in a loop but the furthest one out is stable

Not sure I understand that. But you probably need to tune the threshold parameter to the distanceChanged function. I noticed that in colorWipe you are passing it '10', while in rainbowCycle you are passing it '3'.