It started as ambient light for night trips to toilet. For that part i already had some rgb leds with light sensor attached working smoothly. At some point I wanted to replace top of the mirror light with different led strip (color temperature didn't match main lights), so i bought rgbw strip from chinese supplier and created this small project to control it properly. Core issue to solve - only one wall switch to control both modes. More details in project log.
I used platformio - i think that's the best option today to do arduino boards development.
I flashed latest optiboot to go for almost zero boot time. With stock bootloader it took ~2 seconds to white light to switch on which is really annoying.
To control the state of light before arduino code is running i had to shunt enable pins to ground and led pint to high level with 10k resistors. Otherwise it would blink with some random colors before white light is on
Main code is a state machine and more or less self explanatory.
Simple trick that i hired to control modes with singe switch is double-click hander so to speak. When you switch on the light via wall switch - 12v power suppy starts to feed ardunio nano via linear voltage stab. 5 volts charges almost immideately 470uF cap. Through resistor voltage devider arduino itself knows if 12v power is on or off. White light is switched on then.
When power is switched off - arduino senses that and shuts off all lights and starts monitoring power with long loops of sleep to save capacitor juice. Shottkey diode added to prevent cap to discharge back to liner regulator. Also all pins are connected to driver through resistors to prevent current leak.
If power returns within second or so - arduino stil being up and running - able to switch led mode to ambient (or rainbow) and that concludes the trick