## RGB Lighting

8 posts / 0 new
Author
Message

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

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.

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

my logic goes like this....

{
green reg = 0
blue reg = 0
}

{
red_reg = 256
green reg = upscale_adc - 256
blue reg = 0
}

{
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

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

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.

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