Hi guys,
I'm working on making a night light for my son and am in need of some suggestions. the night light is a space rocket and I'm looking to install leds in the bottom to emulate a rocket engine flame.
Planning on using 3 common anode RGB leds driven with pwm through transistors. (each colour has its own transistor).
however when it comes to modelling the lighting with the code I'm having some problems.
My question is this. If you had to design the code to drive the leds to emulate fire/flames, what method would you use? (using only red and green leds to create red to yellow spectrum.)
My current idea is to just select the colours I want it to fade through and just code each colour manually.
I have been playing with the fader example and got some ok results. However the led keeps dropping to a solid green for a split second and I don't want that. Code is below ;
Are there any other methods I could use to achieve the goal?
int redLed = 5;
int greenLed = 6;
int blueLed = 9;
int fadeRed = 5; // red Fade
int redBrightness = 0; // Red brightness
int fadeGreen = 5; // green Fade
int greenBrightness = 0; // Green Brightness
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
analogWrite(5, redBrightness);
analogWrite(6, greenBrightness);
redBrightness = redBrightness + fadeRed;
if (redBrightness == 150|| redBrightness ==255) {
fadeRed = +fadeRed;
}
greenBrightness = greenBrightness + fadeGreen;
if(greenBrightness ==0|| greenBrightness ==20) {
fadeGreen = -fadeGreen;
}
delay(100);
}