Go Down

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

sg92

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);
delay(random(100));
}

johnwasser

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);
delay(random(100));
}
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

dc42


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.

Grumpy_Mike

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

sg92

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

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview