282Views8Replies

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.


8 Replies

user
steveastroukBest Answer (author)2010-04-18
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);
 

Select as Best AnswerUndo Best Answer

user
lemonie (author)steveastrouk2010-04-18

Ah, you were re-writing it.

L

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)lemonie2010-04-18

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

Select as Best AnswerUndo Best Answer

user
lemonie (author)steveastrouk2010-04-18
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

Select as Best AnswerUndo Best Answer

user
lemonie (author)lemonie2010-04-18

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

L

Select as Best AnswerUndo Best Answer

user
andyspam (author)steveastrouk2010-04-18

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

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)andyspam2010-04-18

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

Select as Best AnswerUndo Best Answer

user
lemonie (author)2010-04-18

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

Select as Best AnswerUndo Best Answer