Combining Codes

If you want it responsive so the leds turn off immediately, you need to remove all the delays and handle the sequence in a non-blocking way using state variables. You can't check a sensor value during the delay, so the code keeps on going until the next time it reads the sensor. You could also have the sequence going in the background nonstop and just AND either 0xFF or 0x00 to the variable depending on the amount of light. 0xFF is all bits on, 0x00 off. Or you could dim the led by flicking the most significant bit and modifying the dimmed state to give values from 0 to 127 instead of all the way to 255 or something similar.

The only thing I'm not understanding yet is why it seems to cycle through five times before it stops. I know it won't stop immediately because it has to finish the cycle, but why five times?

I can look at the code to see if I can figure it out, but the color part of the code confuses me the most.