TBH - what I'd do for something like this is have a single function getting called every 10 milliseconds with setinterval, set up like kind of like a state-machine, which determines if it needs to brighten, dim, or do nothing. Which feels slightly un-Espruino-ey... but I think it'll probably work better. I don't like a solution that's relying on two intervals staying in sync - that's not guaranteed.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I wouldn't be happy with that code either...
TBH - what I'd do for something like this is have a single function getting called every 10 milliseconds with setinterval, set up like kind of like a state-machine, which determines if it needs to brighten, dim, or do nothing. Which feels slightly un-Espruino-ey... but I think it'll probably work better. I don't like a solution that's relying on two intervals staying in sync - that's not guaranteed.