@Rusty. Any luck making advanced functions for the strip?
Here is some updated code .. using the op example.
This version works by just updating the LEDCount, there are extended (more colors) and a slower rainbow added. Also include two functions, "allTo" and "blinkAll".
- The two rainbow additions were done in a way that is more for explanation than good implementation practice.
// Example code for the RGBStrip library used to drive a strip of LEDs using the HL1606 Controller.
// Written by Ben Moyes, Bliptronics.com
// June 28 2010
// ben@bliptronics.com
#include <RGBStrip.h>
#define LEDCount 20 //Set how many LEDs we'll be driving.
//-- NEW - Added this to show the loop count for the LED rainbow effect is not related to the led count
#define RAINBOW_RUN_COUNT 25 //Set how many times the rainbow action will run
//-- END NEW
//We'll use this to store commands before sending to the LEDs.
unsigned char Disp[LEDCount];
//Some constants we will used to create a rainbow pattern.
//A LED following this sequence will phase through a rainbow of colors.
//The S pins needs to be pulsed 128 times to allow each transition to occur before changing to the next step
//in the sequence.
unsigned char rainbow[4] = {
Commandx2 | RedOn | GreenUp | BlueOff,
Commandx2 | RedDown | GreenOn | BlueUp,
Commandx2 | RedOff |GreenDown | BlueOn,
Commandx2 | RedUp | GreenOff | BlueDown
};
//-- NEW - Added this to create a longer rainbow .. color details below
unsigned char longRainbow[6] = {
Commandx2 | RedOn | GreenUp | BlueOff, // red to yellow
Commandx2 | RedDown | GreenOn | BlueOff, // yellow to green
Commandx2 | RedOff | GreenOn | BlueUp, // green to cyan
Commandx2 | RedOff | GreenDown | BlueOn, // cyan to blue
Commandx2 | RedUp |GreenOff | BlueOn, // blue to majenta
Commandx2 | RedOn | GreenOff | BlueDown // majenta to red
};
//-- END NEW
//-- NEW - Added this to create a longer rainbow that runs slower (Updated to Command from Commandx2)
unsigned char longSlowRainbow[6] = {
Command | RedOn | GreenUp | BlueOff, // red to yellow
Command | RedDown | GreenOn | BlueOff, // yellow to green
Command | RedOff | GreenOn | BlueUp, // green to cyan
Command | RedOff | GreenDown | BlueOn, // cyan to blue
Command | RedUp |GreenOff | BlueOn, // blue to majenta
Command | RedOn | GreenOff | BlueDown // majenta to red
};
//-- END NEW
RGBStrip strip(2, 3, 4, 5, LEDCount, Disp); //Create instance of RGBStrip library, tell it which pins are connected to the strip
//S, D, C, L #Leds Buff //how many LEDs, and a pointer to an array where we can store LED commands.
void allTo(int cmd){
for(byte a=0;a < LEDCount; a++)
{
Disp[a%LEDCount] = Command | cmd;
}
strip.displaySend();
}
void blinkAll(int cmd, int times, int blinkRate){
for( int i = 0 ; i < times ; i++ ){
allTo(cmd);
delay(blinkRate/2);
allTo(0);
delay(blinkRate/2);
}
}
void setup()
{
//This will fill our array with the command for all LEDs off.
strip.displaySetSection(0,LEDCount-1,Command);
strip.displaySend(); //Send out the values to the LEDs and latch in the values.
}
void loop()
{
/*
blinkAll(RedOn,5,1000);
blinkAll(BlueOn,7,1000);
blinkAll(BlueOn | RedOn ,3,1000);
*/
unsigned int a,b,c;
//Send out an empty command to all the LEDs to turn them off.
for(a=0;a<LEDCount;a++)
strip.sendByte(Command);
strip.latch();
//Send some colors.
for(a=0;a< 1+ LEDCount/7;a++)
{
strip.sendByte(Command | RedOn);
strip.sendByte(Command | BlueOn);
strip.sendByte(Command | GreenOn);
strip.sendByte(Command | RedOn | BlueOn);
strip.sendByte(Command | RedOn | GreenOn);
strip.sendByte(Command | BlueOn | GreenOn);
strip.sendByte(Command | BlueOn | GreenOn);
}
strip.latch();
delay(2000);
// **** Do a rainbow.****
// This is a little mind-bending, I'll try to explain:
// Led 0 performs a color transition/fade, but when it is only 1/4 done, we push in a zero
// which doesnt get loaded into led 0, but then gets loaded into led 1
// the trasition continues and we repeat the sequece of pushing a zero and continuing to do the transition two more time.
// When LED0 is finished the transition, we then load it with another transition and repeat the whole sequece above.
for(a=0;a < RAINBOW_RUN_COUNT; a++)
{
strip.sendByte(rainbow[a%4]); //modulo will give us values of 0 to 3 as we step through loop..look it up!
strip.latch();
strip.runfader(16,2); //Fade to 25% (there is 64 fade steps in a 2x command, 128 in a normal command
strip.sendByte(0); //Zero never gets loaded into a LED
strip.latch(); //Load the LEDs.
strip.runfader(16,2); //fade to 50% done
strip.sendByte(0);
strip.latch();
strip.runfader(16,2); //fade to 75%
strip.sendByte(0);
strip.latch();
strip.runfader(16,2); //fade to 100%
}
//-- NEW
blinkAll(RedOn,1,500);
// **** Do a long rainbow.****
for(a=0;a < RAINBOW_RUN_COUNT; a++)
{
strip.sendByte(longRainbow[a%6]); //modulo will give us values of 0 to 5 as we step through loop..look it up!
strip.latch();
strip.runfader(16,2); //Fade to 25% (there is 64 fade steps in a 2x command, 128 in a normal command
strip.sendByte(0); //Zero never gets loaded into a LED
strip.latch(); //Load the LEDs.
strip.runfader(16,2); //fade to 50% done
strip.sendByte(0);
strip.latch();
strip.runfader(16,2); //fade to 75%
strip.sendByte(0);
strip.latch();
strip.runfader(16,2); //fade to 100%
}
blinkAll(BlueOn,2,500);
// **** Do a long slow rainbow.****
// -- updated from 16 to 32 below to run twice as many steps in the fader
for(a=0;a < RAINBOW_RUN_COUNT; a++)
{
strip.sendByte(longSlowRainbow[a%6]); //modulo will give us values of 0 to 5 as we step through loop..look it up!
strip.latch();
strip.runfader(32,2); //Fade to 25% (there is 64 fade steps in a 2x command, 128 in a normal command
strip.sendByte(0); //Zero never gets loaded into a LED
strip.latch(); //Load the LEDs.
strip.runfader(32,2); //fade to 50% done
strip.sendByte(0);
strip.latch();
strip.runfader(32,2); //fade to 75%
strip.sendByte(0);
strip.latch();
strip.runfader(32,2); //fade to 100%
}
//Set some groups of LEDs.
//They are set in memory first, then values for all leds are sent out with displaySend()
//Set LEDs 0 to 19 to fade up to blue at double speed
strip.displaySetSection(0,LEDCount-1,Command | BlueUp);
strip.displaySend(); //Send out to LEDs
strip.runfader(128,5); //Pulse the fade line 128 times with a 2mS delay each time.
// Fade DOWN from blue.
strip.displaySetSection(0,LEDCount-1,Command|BlueDown);
strip.displaySend();
strip.runfader(128,5);
//Fade up to RED
strip.displaySetSection(0,LEDCount-1,Command|RedUp);
strip.displaySend();
strip.runfader(128,5);
//Fade down from RED.
strip.displaySetSection(0,LEDCount-1,Command|RedDown);
strip.displaySend();
strip.runfader(128,5);
strip.displaySetSection(0,LEDCount-1,Command);
strip.displaySend();
//Bounce a blue LED up and down.
for(b=0;b<5;b++)
{
for(a=0;a < LEDCount; a++)
{
Disp[a%LEDCount] = Command | BlueOn;
strip.displaySend();
delay(50+ a*a/5);
Disp[a%LEDCount] = Command |BlueOff;
}
for(a=LEDCount-1;a > 0; a--)
{
Disp[a%LEDCount] = Command | BlueOn;
strip.displaySend();
delay(50+ a*a/5);
Disp[a%LEDCount] = Command | BlueOff;
}
}
}
Note: I am not working with the strip much, opting for the pwm versions. With this strip, I was able to get a fading and specific colors without using the fade function (software PWM) .. but only in the loop.
Interested to see what you come up with.