I am using LED strips (6803) and in order for them to come on, you need to specify the LED number and then the LED color.
I got the LED to come on, but I can't figure out the colors without any consistency. Apparently they use a 15 bit color code, but I've googled it and the results I come up with always result in a white LED.
I've used the examples that come with the library, but they don't allow you to manually insert a color, EG solid white. They all fade around a color wheel..
I tried using Serial.write to see what it was sending to the LED, for red I got 99299 but although the colors were close, they were still a bit off. (eg, RED was more faded and orangy.
Each colour has a number of bits to control how bright it is. As you have three colours and 15 bits then each colour has 5 bits associated with it.
With 5 bits you can specify 32 different brightnesses. So if you just send the numbers 0 to 31 in turn you should get all the different shades of red.
Now it gets a bit complex because you don't understand about binary bits yet. But the numbers from 32 to 1023 in steps of 32 define all the shades of green. Then the numbers from 1024 to 32768 in steps of 1024 give you all the shades of blue.
You can work out a colour number from these components, Lets say you want 50% red 25% green and 10% blue, convert them first into steps of 32
Red = 16
Green = 8
Blue = 4 ( well 3.2 but we are dealing in integers)
So the 15 bit colour value is equal to:-
16 + ( 32 * 8 ) + ( 1024 * 4 )
or
colour = Red + 32 * Green + 1024 * Blue = 4368
If i enter in all the numbers 1-31 i get all the different shades of GREEN
color = ( B * 1024) + (R * 32) + G
appears to be the formula, because when i do
color = ( 31 * 1024) + (0 * 32) + 0
I get full blue
and when i do
color = (0 * 1024) + (31 * 32) + 0
i get full red.
However, when I try to say, for instance get the led strip to put out "yellow" I cant get the code to work, even though i've seen the strip put out the color yellow when it is running the fade program in the example.
The RGB code for a yellow is
R 251
G 232
B 75
I then turned those into percents:
R 44.9%
G 41.6%
B 13.4%
Then I multiplied each number by 31 and got:
R 15
G 13
B 4
then
color = ( B * 1024) + (R * 32) + G
color = (4 * 1024) + (15 * 32) + 13
color = 4589
but when i put that into the sketch, i get a whitish blue color.... not yellow.
If i use the original formula
color = (B * 1024) + (G * 32) + R
color = (4 * 1024) = (13 * 32) + 15
color = 4527
it's just a little less red and a little less blue ( you gotta be staring at the LED's to tell)
Thanks for the setting me on the right track, guys.
I was able to get the colors working correctly.
I'm using a cheap led strip, so the colors arent quite right. Blue is overly bright so you have to bring it way down to get purples and light blues....
For the yellows, the green overshadows the red so you got to turn the green down.
Yes that happens with all LEDs the balance is never right. Sometimes you can compensate by having diffrent resistor values in the currents.
Best way is to have three pots and adjust them interactively. Some colours are impossible to get, like brown. You might also like to look at gamma correction that attempts to compensate for the fact that the eye's sensitivity is logarithmic and the LED's output is linear.
No you don't put the pot on the LED strip. You connect it to the analogue input, one per pot. Then read the pot value and work out the colour number from the pot values.
To make the range add up divide the pot readings because they are 0 to 1023.
Red = analogRead(A0) >> 5;
Green = analogRead(A1) >> 5;
Blue = analogRead(A2) >> 5;
Thanks for the tip, this will make finding colors so much easier.
#include <TimerOne.h>
#include "LPD6803.h"
//Example to control LPD6803-based RGB LED Modules in a strand
// Original code by Bliptronics.com Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!
// Code cleaned up and Object-ified by ladyada, should be a bit easier to use
/*****************************************************************************/
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 4; // 'yellow' wire
int clockPin = 5; // 'green' wire
// Don't forget to connect 'blue' to ground and 'red' to +5V
long int q = 0;
long int m = 0;
int redpotPin = A2;
int bluepotPin = A3;
int greenpotPin = A4;
int color;
int numpix = 50;
// Timer 1 is also used by the strip to send pixel clocks
// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
LPD6803 strip = LPD6803(numpix, dataPin, clockPin);
void setup() {
Serial.begin(9600);
strip.setCPUmax(60); // start with 50% CPU usage. up this if the strand flickers or is slow
// Start up the LED counter
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
}
void loop() {
pots();
Serial.println(color);
for (q=0; q < numpix; q++){
strip.setPixelColor(q, color);
strip.show(); // write all the pixels out
//Serial.println(q);
/*if (q > 50) {
while (m < 50) {
strip.setPixelColor(m, color);
delay (100);
m = m + 1;
q = 0;
strip.show();
}
}
m = 0;*/
//if (q < numpix) {
//q = q + 1;
//}
delay (40);
}
}
int pots() {
int Red = analogRead(redpotPin) >> 5;
int Green = analogRead(greenpotPin) >> 5;
int Blue = analogRead(bluepotPin) >> 5;
color = Blue*1024 + Red*32 + Green;
//Serial.println(color);
//return color;
}
Do you have to debounce the potentiometers? Because, if i don't have a delay of at least 40, the lights toward the end of the strip flicker?
#include <TimerOne.h>
#include "LPD6803.h"
//Example to control LPD6803-based RGB LED Modules in a strand
// Original code by Bliptronics.com Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!
// Code cleaned up and Object-ified by ladyada, should be a bit easier to use
/*****************************************************************************/
// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 4; // 'yellow' wire
int clockPin = 5; // 'green' wire
// Don't forget to connect 'blue' to ground and 'red' to +5V
long int q = 0;
long int m = 0;
int redpotPin = A2;
int bluepotPin = A3;
int greenpotPin = A4;
int color;
// Timer 1 is also used by the strip to send pixel clocks
// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
LPD6803 strip = LPD6803(50, dataPin, clockPin);
void setup() {
Serial.begin(9600);
strip.setCPUmax(60); // start with 50% CPU usage. up this if the strand flickers or is slow
// Start up the LED counter
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
}
void loop() {
pots();
Serial.println(color);
strip.setPixelColor(q, color);
strip.show(); // write all the pixels out
//Serial.println(q);
if (q > 50) {
while (m < 50) {
strip.setPixelColor(m, color);
delay (100);
m = m + 1;
q = 0;
strip.show();
}
}
m = 0;
q = q + 1;
delay (100);
}
int pots() {
int Red = analogRead(redpotPin) >> 5;
int Green = analogRead(greenpotPin) >> 5;
int Blue = analogRead(bluepotPin) >> 5;
color = Blue*1024 + Red*32 + Green;
//Serial.println(color);
//return color;
}