3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

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.



8 answers
sort by: active | newest | oldest
Apr 18, 2010. 6:31 AMsteveastrouk says:
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);
 
Apr 18, 2010. 6:38 AMlemonie says:
Ah, you were re-writing it.

L
Apr 18, 2010. 7:56 AMsteveastrouk says:
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
Apr 18, 2010. 7:59 AMsteveastrouk says:
You can start to do colour mixing once you have the basic ideas straight.
Steve
Apr 18, 2010. 9:40 AMlemonie says:
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

Apr 18, 2010. 9:41 AMlemonie says:
But that doesn't seem to have preserved the line breaks.

L
Apr 18, 2010. 6:37 AMlemonie says:
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


Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!