Author Options:

RGB led wont change color correctly. Answered

 I an trying to make an Arduino lamp that changes color with the turning of an potentiometer to make the RGB go from green to red to blue but it goes from green to yellow to purple.

the code is at andyspam.com/code.html since instructables wont let me paste.

please help,
thanks in advanced.


The logic is faulty. Since your LEDs only want to be on in a certain band of operation, check them over that band.

digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
digitalWrite(bluePin, LOW);

if (sensorValue >= 100) && {sensorValue <400)
   digitalWrite(greenPin, HIGH);
if (sensorValue >= 400) && {sensorValue <700)
   digitalWrite(redPin, HIGH);

if (sensorValue >= 700) && {sensorValue <1024)       digitalWrite(bluePin,HIGH);

I posted something and it made a complete total balls of it when I saw it on here  - looked OK in preview too.

Is there a way of preserving formatting ? like the old <pre> tags ?


There is
 Text in a pre element is displayed in a fixed-width font, and it preserves both      spaces and line breaks 
Click the Source button and use a <PRE> tag.


But that doesn't seem to have preserved the line breaks.


Thank you so much!!!!!!!
I'm a beginner so my codes are a little buggy.

You can start to do colour mixing once you have the basic ideas straight.

Where did steve's answer go?

If I read you code correctly, at values above 700, these conditions are all true:
sensorValue > 100 (greenPin,HIGH)
sensorValue > 400) (redPin, HIGH)
sensorValue > 700) (bluePin, HIGH)

You want some of them to go LOW at higher values, this code just turns each colour on progressively without turning them off again.