Go Down

Topic: RGB led... what gives????????? - (SOLVED) (Read 584 times) previous topic - next topic

HazardsMind

#15
Feb 05, 2013, 09:15 pm Last Edit: Feb 05, 2013, 09:17 pm by HazardsMind Reason: 1
All your wires must be in the PWM pins. 8 is not PWM
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Ruffsta


AWOL

Is this going to be a "20 questions" thread?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Ruffsta

#18
Feb 05, 2013, 09:26 pm Last Edit: Feb 05, 2013, 10:06 pm by Ruffsta Reason: 1
nope, it can be locked now.. i'll do fading another day, just glad i finally have this working the way i wanted it to..

oh, found this:
Code: [Select]
#define GREEN 3
#define BLUE 5
#define RED 6
#define delayTime 20

void setup() {

 pinMode(GREEN, OUTPUT);
 pinMode(BLUE, OUTPUT);
 pinMode(RED, OUTPUT);
 digitalWrite(GREEN, HIGH);
 digitalWrite(BLUE, HIGH);
 digitalWrite(RED, HIGH);
}

int redVal;
int blueVal;
int greenVal;

void loop() {

 int redVal = 255;
 int blueVal = 0;
 int greenVal = 0;
 for( int i = 0 ; i < 255 ; i += 1 ){
   greenVal += 1;
   redVal -= 1;
   analogWrite( GREEN, 255 - greenVal );
   analogWrite( RED, 255 - redVal );

   delay( delayTime );
 }

 redVal = 0;
 blueVal = 0;
 greenVal = 255;
 for( int i = 0 ; i < 255 ; i += 1 ){
   blueVal += 1;
   greenVal -= 1;
   analogWrite( BLUE, 255 - blueVal );
   analogWrite( GREEN, 255 - greenVal );

   delay( delayTime );
 }

 redVal = 0;
 blueVal = 255;
 greenVal = 0;
 for( int i = 0 ; i < 255 ; i += 1 ){
   redVal += 1;
   blueVal -= 1;
   analogWrite( RED, 255 - redVal );
   analogWrite( BLUE, 255 - blueVal );

   delay( delayTime );
 }
}


yeah it fades through all the colors.. but i wanted to control the colors individually..
ex:
Code: [Select]
 //turn red on
 digitalWrite(red, LOW);
 digitalWrite(green, HIGH);
 digitalWrite(blue, HIGH);
 delay(500);


but say i wanted orange or pink or pure yellow.. is there a chart or something.. like put numbers in there instead of HIGH/LOW?

PaulS

Quote
but say i wanted orange or pink or pure yellow.. is there a chart or something.. like put numbers in there instead of HIGH/LOW?

The digitalWrite() function only turns pins on or off. The analogWrite() function, on the other hand, allows you to put numbers in there.

On an RGB LED, there is no such thing as "pure yellow". You need to get three potentiometers, and adjust them to get colors you like. Make note of the numbers, and you can get "pure yellow" or pink or orange.

There are charts that show what r, g, and b values make up colors, for web pages, etc. Those charts assume perfectly linear response to change in r, g, and b values. An LED will NOT exhibit a linear response, nor will the human eye. That's why you need to experiment to get the colors you want.

Go Up