Go Down

Topic: 4 Pin RGB LED Flickering Flame effect, help! (Read 2447 times) previous topic - next topic


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: [Select]

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);


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: [Select]

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);
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


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


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


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131