White fade with red "flame"

Hello everyone out there who understands coding better than I do.

Plan:

  • I want a white LED to fade in and out ONLY ONCE, then turn off (which is the main obstacle in my coding knowledge.... I can't use millis, and also, the "exit(0)" function seems to be against me as well)
  • Then, as the white LED starts fading out, a red LED would make this flame effect continuously until the whole system is fed with current. (This effect works pretty nicely so far.... just think there's a better way of approach.

Code:

int red = 3;
int white = 5;
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

void setup(){
pinMode(red, OUTPUT);
pinMode(white, OUTPUT);
}

void loop() {{
analogWrite(white, brightness);

brightness = brightness + fadeAmount;

if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}

analogWrite(red, random(120)+135);
delay(random(50));
}

Thank you SOOO much for any help.... other than that, what book, app, whatever, would you recommend for learning C/C++ effectively?

Have a great day.
Mark

Why can't you use millis()?

You need to in order to achieve the white fading out while the red also fades (either that, or an agonizingly long repetitive program)

DrAzzy:
Why can't you use millis()?

I'm kinda new to arduino :wink: But thank you and have a great one.

mastermerak:
I'm kinda new to arduino :wink: But thank you and have a great one.

New or not, if I can figure it out, anyone can. It's really not that difficult at all. And if you want your Arduino to do more than one thing at a time, you have to use it. I'm no guru by any stretch but I don't know of any way to do what you want without it.

Using millis() really isn't hard.

Everyone who uses Arduino, probably on their first or second sketch for something they're doing for themselves (rather than copying from book/tutorial/etc), will end up trying to do something that can't be done with delay and will at that point learn how to use millis(). It is not something to delay "because you're new".

DrAzzy:
It is not something to delay millis "because you're new".

:wink: