question digital led strip
Moderators: adafruit_support_bill, adafruit

question digital led strip

by five10 on Fri Nov 30, 2012 4:57 pm

hi,
i hope someone can help me, i'm really new to arduino. I will try to explain what i want to do but my english is pretty poor. I have 6 meters of the digital rgb stripe and use the sample code to make the rainbow cycle along the stripe. what i'm trying to do is to make two color cycles at once each 3 meters. for example led 1 starts with red, led 97 should start with red at the same moment. i hope you understand what i mean.just to rainbowcolor cycles which are synced, each 96 leds long.this is the code i'm using at the moment for the full 192 leds cycle
Code: Select all | TOGGLE FULL SIZE
#include [color=#006699]"LPD8806.h"[/color]
#include [color=#006699]"SPI.h"[/color]


[color=#7E7E7E]/*****************************************************************************/[/color]

[color=#7E7E7E]// Number of RGB LEDs in strand:[/color]
[color=#CC6600]int[/color] nLEDs = 192;

[color=#7E7E7E]// Chose 2 pins for output; can be any valid output pins:[/color]
[color=#CC6600]int[/color] dataPin  = 2;
[color=#CC6600]int[/color] clockPin = 3;

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

[color=#7E7E7E]// You can optionally use hardware SPI for faster writes, just leave out[/color]
[color=#7E7E7E]// the data and clock pin parameters.  But this does limit use to very[/color]
[color=#7E7E7E]// specific pins on the Arduino.  For "classic" Arduinos (Uno, Duemilanove,[/color]
[color=#7E7E7E]// etc.), data = pin 11, clock = pin 13.  For Arduino Mega, data = pin 51,[/color]
[color=#7E7E7E]// clock = pin 52.  For 32u4 Breakout Board+ and Teensy, data = pin B2,[/color]
[color=#7E7E7E]// clock = pin B1.  For Leonardo, this can ONLY be done on the ICSP pins.[/color]
[color=#7E7E7E]//LPD8806 strip = LPD8806(nLEDs);[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
  [color=#7E7E7E]// Start up the LED strip[/color]
  strip.[color=#CC6600]begin[/color]();

  [color=#7E7E7E]// Update the strip, to start they are all 'off'[/color]
  strip.show();
}


[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]() {

  

 
  rainbowCycle(0);  [color=#7E7E7E]// make it go through the cycle fairly fast[/color]
}

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





[color=#7E7E7E]/* Helper functions */[/color]

[color=#7E7E7E]//Input a value 0 to 384 to get a color value.[/color]
[color=#7E7E7E]//The colours are a transition r - g -b - back to r[/color]

uint32_t Wheel(uint16_t WheelPos)
{
  [color=#CC6600]byte[/color] r, g, b;
  [color=#CC6600]switch[/color](WheelPos / 128)
  {
    [color=#CC6600]case[/color] 0:
      r = 127 - WheelPos % 128;   [color=#7E7E7E]//Red down[/color]
      g = WheelPos % 128;      [color=#7E7E7E]// Green up[/color]
      b = 0;                  [color=#7E7E7E]//blue off[/color]
      [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 1:
      g = 127 - WheelPos % 128;  [color=#7E7E7E]//green down[/color]
      b = WheelPos % 128;      [color=#7E7E7E]//blue up[/color]
      r = 0;                  [color=#7E7E7E]//red off[/color]
      [color=#CC6600]break[/color];
    [color=#CC6600]case[/color] 2:
      b = 127 - WheelPos % 128;  [color=#7E7E7E]//blue down [/color]
      r = WheelPos % 128;      [color=#7E7E7E]//red up[/color]
      g = 0;                  [color=#7E7E7E]//green off[/color]
      [color=#CC6600]break[/color];
  }
  [color=#CC6600]return[/color](strip.Color(r,g,b));
}


thx for your help
five10
 
Posts: 4
Joined: Fri Nov 30, 2012 4:46 pm

Re: question digital led strip

by mohawkpiper on Fri Nov 30, 2012 6:25 pm

heya,
that's pretty simple i think....
in this line...

Code: Select all | TOGGLE FULL SIZE
strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) );


change it to this...

Code: Select all | TOGGLE FULL SIZE
strip.setPixelColor(i, Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );


i added a number '2' between 'i' and '384'. whatever number you put there should be how many rainbows you have.

G
User avatar
mohawkpiper
 
Posts: 72
Joined: Sat Oct 13, 2012 3:28 am

Re: question digital led strip

by five10 on Fri Nov 30, 2012 6:41 pm

thx a lot, works perfect, but i forgot one import thing...the second cycle(from led 97 to 192) must run in the opposit direction than the first part of the stripe..sorry for that
five10
 
Posts: 4
Joined: Fri Nov 30, 2012 4:46 pm

Re: question digital led strip

by mohawkpiper on Fri Nov 30, 2012 6:48 pm

ok im not at home with my stuff right now to give it test it myself...
but try this....
if it works, awesome, if not maybe someone else can chime in or you can wait til i get off work to figure it out with my leds myself...

so change that same line to this...

Code: Select all | TOGGLE FULL SIZE
if(i<strip.numPixels()/2){
  strip.setPixelColor(i, Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );
} else {
  strip.setPixelColor(strip.numPixels()-i-1, Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );
}


i think that should do it
User avatar
mohawkpiper
 
Posts: 72
Joined: Sat Oct 13, 2012 3:28 am

Re: question digital led strip

by five10 on Fri Nov 30, 2012 6:54 pm

first part of the stripe runs now reverse but the second part is off:-(
five10
 
Posts: 4
Joined: Fri Nov 30, 2012 4:46 pm

Re: question digital led strip

by mohawkpiper on Fri Nov 30, 2012 6:58 pm

i think i wrote the second half over the first half...
this part in the latest version...

Code: Select all | TOGGLE FULL SIZE
strip.setPixelColor(strip.numPixels()-i-1, Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );


change it to this....

Code: Select all | TOGGLE FULL SIZE
strip.setPixelColor(strip.numPixels()-i-1+(strip.numPixels()/2), Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );
User avatar
mohawkpiper
 
Posts: 72
Joined: Sat Oct 13, 2012 3:28 am

Re: question digital led strip

by mohawkpiper on Fri Nov 30, 2012 7:14 pm

if that doesnt work you can try this...
(redo the whole for loop for i...)

so originally it was this...

Code: Select all | TOGGLE FULL SIZE
for(i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 384-color wheel[/color]
      // (thats the i / strip.numPixels() part)[/color]
      // Then add in j which makes the colors go around per pixel[/color]
      // the % 384 is to make the wheel cycle around[/color]
      strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) );
    } 


change it to this...

Code: Select all | TOGGLE FULL SIZE
for(i = 0; i < strip.numPixels() / 2; i++) {
    strip.setPixelColor(strip.numPixels()-i-1,Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );
    strip.setPixelColor(i, Wheel( ((i * 2 * 384 / strip.numPixels()) + j) % 384) );
}



if neither of those work ill stop as im probably just confusing the whole situation.
sorry but im an extremely visual person and trial and error is totally my game. i rarely get things right the first try.

if i dont see a reply later tonight that says one of those worked and i dont see a reply from someone else who got it....
ill work on it and post it when i get it.

G
User avatar
mohawkpiper
 
Posts: 72
Joined: Sat Oct 13, 2012 3:28 am

Re: question digital led strip

by five10 on Fri Nov 30, 2012 7:17 pm

works like a charm..thx a lot for you're help..you're my man
five10
 
Posts: 4
Joined: Fri Nov 30, 2012 4:46 pm



cron