RGB Lighting

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a maths problem guys. need some understanding

I have a pot which i will read from the avr adc. I will keep this adc 8 bits long. When i turn the knob i want the the rgb colours to change in accordance with the adc value

Now for the rgb lighting i will be outputing the 3 colour registers on their respective pwm lines

how do i divide the adc values among the 3 colour registers(all 3 regiters are 8 bit long) to get the best colour mixing.

Thanks

Rodney Almeida

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

how do i divide the adc values among the 3 colour registers(all 3 regiters are 8 bit long) to get the best colour mixing.

You haven't given us enough information as to how you intend the colour to vary with controller position.

One way you could do it would be to split the 8 bits as R:G:B 2:3:2 for example.

But it really does depend how you want it to vary. Another option would be a 256 entry lookup table.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i was thinking something like this(pls bear with me)

my logic goes like this....

get adc_value

upscale_acd=(adc_value x 3)

if (upscale_adc <= 256) then
{
red_reg = upscale_adc
green reg = 0
blue reg = 0
}

if (upscale_adc > 256) and (upscale_adc <= 512) then
{
red_reg = 256
green reg = upscale_adc - 256
blue reg = 0
}

if (upscale_adc > 512) then
{
red_reg = 256
green reg = 256
blue reg = upscale_adc - 512
}

so
for adc_value = 40.. R:G:B = 120:0:0
for adc_value = 100.. R:G:B = 256:44:0
for adc_value = 200.. R:G:B = 256:256:88

let me know what u think

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

just thinking.. the above logic will always have the redled on for any +ve adc value

no that cannot be right! the logic is no good

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to start by deciding what kind of colour sweep you want. Do you want it to start red at one end of the control and then sweep through the colours of the rainbow or what? When you have decided on the sequence then you can determine the algorithm to implement it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes, if at one end of the pot control i start from red then a mix of colours between red green and blue and finally end up with blue.

I think i will have to make a lookup table for such a scenerio.

rodney

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So your color sweep can probably very simply
described in the HSB (hue,saturation,brightness)
color space. Then by HSB to RGB conversion you
get the table (in theory).

I think there are many projects wit an RGB LED
and a sweep as you want. Probably using google
one should be able to fing such a thing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Converting from HSB to RGB requires floating-point math; you're best off precomputing a table of colors on your PC and storing it in ROM.