Pages: [1] 2   Go Down
Author Topic: RGB led... what gives????????? - (SOLVED)  (Read 531 times)
0 Members and 1 Guest are viewing this topic.
Rhode Island - USA
Offline Offline
Full Member
***
Karma: 0
Posts: 156
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, i am using an RGB led (4 pins)..

this code works with "pinMode":
Code:
int red = 8;
int green = 9;
int blue = 10;


void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}

void loop() {
//RED
pinMode(red, HIGH);
pinMode(green, LOW);
pinMode(blue, LOW);
delay(500);
//OFF................
pinMode(red, LOW);
pinMode(green, LOW);
pinMode(blue, LOW);
delay(50);
//GREEN
pinMode(red, LOW);
pinMode(green, HIGH);
pinMode(blue, LOW);
delay(500);
//OFF................
pinMode(red, LOW);
pinMode(green, LOW);
pinMode(blue, LOW);
delay(50);
//BLUE
pinMode(red, LOW);
pinMode(green, LOW);
pinMode(blue, HIGH);
delay(500);
//OFF................
pinMode(red, LOW);
pinMode(green, LOW);
pinMode(blue, LOW);
delay(50);
}

now this is the same EXACT code, but with "digitalWrite" - but it DOESN'T work..
Code:
int red = 8;
int green = 9;
int blue = 10;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  //turn red on
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
//OFF................
    digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  //turn green on
  digitalWrite(red, LOW);
  digitalWrite(green, HIGH);
  digitalWrite(blue, LOW);
  delay(500);
//OFF................
      digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  //turn blue on
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, HIGH);
  delay(500);
//OFF................
      digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  }
« Last Edit: February 05, 2013, 02:51:36 pm by Ruffsta » Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12463
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The first example is nonsense - you shouldn't pass "LOW" or "HIGH" to pinMode().  Or rather you'd have to look
at the definitions of LOW, HIGH, INPUT, OUTPUT to work out what's actually happening.

How is this LED connected?  You are using current limiting resistors per LED aren't you (otherwise
you can burn out the LED and/or Arduino)?
Logged

[ I won't respond to messages, use the forum please ]

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

Quote
ok, i am using an RGB led (4 pins)..
Common anode or common cathode?
Logged

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

my connections are fine.. and yes i am using resistors.. i may be new, but i'm not stupid
but it's odd that the lights come on EXACTLY the way i want them to with pinMODE but not with digitalWrite.. just can't figure out WHY it's doing that..
Logged

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

common anode..
Logged

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

What does happen with digitalWrite, and have you spotted a pattern?
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: 156
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

colors are off and i tried moving the wires around.. but nada
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34542
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What you are doing with pinMode is setting the pins to be outputs or inputs, even when you write high and low with them, So they will turn to outputs, sink current and light the LED. When they are inputs they are high impedance and they don't sink current and so the LED is off.
It is not the real way to do it though.

How is it wired up?
Code:
pinMode(red, HIGH);
pinMode(green, LOW);
pinMode(blue, LOW);
Will not turn on just red if it wired correctly.
Anode to +5V, red cathode to resistor to arduino output, same for the other two colours.
« Last Edit: February 05, 2013, 01:20:16 pm by Grumpy_Mike » Logged

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

my connections are as follows..

red connected to resistor to arduino pin 8
common anode connected to 5v
green connected to resistor to arduino pin 9
blue connected to resistor to arduino pin 10
Logged

Offline Offline
God Member
*****
Karma: 19
Posts: 785
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What are you expecting vs what you are getting.  As written the second code should give you blue-green then white then purple then white then yellow.  The way you describe the hookup the LEDs will light when written LOW and turn off when written HIGH.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3766
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

These should be reversed if you have the anode HIGH.
Code:
void loop() {
  //turn red on
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
//OFF................
    digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  //turn green on
  digitalWrite(red, LOW);
  digitalWrite(green, HIGH);
  digitalWrite(blue, LOW);
  delay(500);
//OFF................
      digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  //turn blue on
  digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, HIGH);
  delay(500);
//OFF................
      digitalWrite(red, LOW);
  digitalWrite(green, LOW);
  digitalWrite(blue, LOW);
  delay(500);
  }

Flip the Highs and Lows
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

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

yep... the low's and high's had to be reversed... thank you

and i shortened the code as well..
Code:
int red = 8;
int green = 9;
int blue = 10;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  //turn red on
  digitalWrite(red, LOW);
  digitalWrite(green, HIGH);
  digitalWrite(blue, HIGH);
  delay(500);
 
  //turn green on
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
  digitalWrite(blue, HIGH);
  delay(500);
 
  //turn blue on
  digitalWrite(red, HIGH);
  digitalWrite(green, HIGH);
  digitalWrite(blue, LOW);
  delay(500);
 
  }

just need to learn how to fade them instead of them just blinking the colors..
« Last Edit: February 05, 2013, 03:04:14 pm by Ruffsta » Logged

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

Quote
just need to learn how to fade them
try analogWrite, on appropriate pins
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: 156
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

nothing happens...
Logged

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

Feel free to add any details you feel necessary.
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.

Pages: [1] 2   Go Up
Jump to: