Pages: 1 [2]   Go Down
Author Topic: RGB led... what gives????????? - (SOLVED)  (Read 454 times)
0 Members and 1 Guest are viewing this topic.
Queens, New York
Online Online
Faraday Member
**
Karma: 65
Posts: 2921
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All your wires must be in the PWM pins. 8 is not PWM
« Last Edit: February 05, 2013, 03:17:29 pm by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Rhode Island - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 157
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

on my mega 2560... 8-13 are pwm's..
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this going to be a "20 questions" thread?
Logged

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

Rhode Island - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 157
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
 //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?
« Last Edit: February 05, 2013, 04:06:06 pm by Ruffsta » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45978
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: 1 [2]   Go Up
Jump to: