Dim LED without using delay() function.

Hi. I am trying to make a code such that the LED change it’s lighting pattern by pushing a switch. The pattern has to be as follow:

LED OFF → (push and release button) →
LED dims up in one second and dims down in one second (repeat dimming up and down until next action) → (push and release button) →
LED ON → (push and release button) →
LED OFF → (push and release button) →
(repeat same process…)

I wrote a code with delay() function, but I need to rewrite it without the delay() function because the button doesn’t work during the delay time. I can guess this could be solved by using millis() function, but I don’t know how to apply this function for PWM.

The configuration and code are attached.

I would appreciate if you could help me. Thanks.

dimming.ino (2.2 KB)