Fading a LED In and out, with duration variables

You would use millis() for timing but no while loop in each of my suggested states thus not blocking the rest of the code

Each time the code for the current state is executed it checks whether it is time to do something. The fading states would change the brightness of the LED when the correct time had passed and once the brightness reached the end value would switch to the appropriate hold state. In those states when the state code was executed next it would check whether the hold period had passed and switch to the appropriate fading state

Remember, only one state would be active at any one time

1 Like