RGB led wont change color correctly.

 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.



sort by: active | newest | oldest
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);
 
Ah, you were re-writing it.

L
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 ?

Steve
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.

L

lemonie lemonie7 years ago
But that doesn't seem to have preserved the line breaks.

L
andyspam (author)  steveastrouk7 years ago
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.
Steve
lemonie7 years ago
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.

L