Pages: [1]   Go Down
Author Topic: 4 Pin RGB LED Flickering Flame effect, help!  (Read 1019 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys this is my first post on here (go easy), I'm trying to make a flickering LED effect using a 4pin LED, I know normal LED flame tutorials have been done to death but I can't seem to find one for 4pins, I'm using these ones because in my experience theyre a lot brighter. So! Out of curiosity I tried this code with the LED, it works in terms of flickering, but it goes all different colours as opposed to going traditional red/yellow. I've got another 2 of these LED's if its a case of setting them individually to a colour then getting them to flicker. Can anyone point me in the right direction? Any help is appreciated!  Thanks
Code:

int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 11;

void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}

void loop() {
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
delay(random(100));
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To keep the light in the Red/Orange/Yellow range you probably want to make sure that the Green and Blue components are the same intensity:
Code:
int ledPinRed = 10;
int ledPinGreen = 9;
int ledPinBlue = 11;

void setup()
{
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinGreen, OUTPUT);
pinMode(ledPinBlue, OUTPUT);
}

void loop() {
int Red = random(120)+135;
int Yellow = random(120)+135;
analogWrite(ledPinRed, Red);
analogWrite(ledPinGreen, Yellow);
analogWrite(ledPinBlue, Yellow);
delay(random(100));
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To keep the light in the Red/Orange/Yellow range you probably want to make sure that the Green and Blue components are the same intensity:

Unfortunately, green and blue do not mix to give yellow, that gives cyan. You need to mix red and green to get yellow. Try selecting a random red level, then a random green level that is no greater than the red level you picked. Either don't use blue at all, or use a random blue level that is no greater than the green level you picked.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 516
Posts: 31579
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would not flash the blue one at all and limit the range of the green LED to keep all he colours flame like.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah thanks so much guys! The code johnwasser gave worked a treat! It now flickers red/yellow  smiley
Logged

Pages: [1]   Go Up
Jump to: