I need helpt to optimize and change a Fade function.

Hi

I’ve posted some before and got helped by it so Im hope I can get some help with this to.

The code below is a software that is implementing smart control of a entire light system on a old car without electronics. I’ve had some trouble figuring out how to get the InteriorLightFadeOut() function to not lock up the rest of the code during active state.

Further more, I really could use some help how to optimize and perhaps get Classy about it :stuck_out_tongue: I know I can put some of this code in classes but not sure what and how. I have trouble understanding classes and their use.

I will use direct I/O with bits when progressing my code, it is a smart way to get less code and make several ports high or low at the same time.

I’m posting my code for you to look at.

Thanks in advance

BelysningKomplett_V0-1.ino (9.01 KB)

Use the millis model you've used elsewhere to call a routine to fade the interior light out - rather as you are doing in fact.

However, each time you call it, rather than doing the fade with delay, just reduce the fade value and analogWrite it. You'll need to make FadeValue a global. Set it to 255 when you turn the interior lights on and don't let the fade routine reduce it below zero. That should do it.

Wildbill:

Ok, I'll will try that solution. I thought about it but I guess I thought it could somehow mezz up the rest of the code but as I have more millis function working happily besides each other this should work to :smiley:

Thanks for helping me.