We will now find out how to control the LEDs. If you are just interested in uploading the code and actually watching the LEDs, then go straight to the next step.

Before we can start programming, we need to know the hardware first. More specifically, we should know how the LEDs are connected to the microcontroller. We can check this by following the traces on the circuit board, or by checking the schematic someone else already made (credits). The complete schematic is in PDF, but I aso added a simplified version with the information we need.

We can see that they use the ATmega88 as microcontroller. The LEDs are controlled with some MOSFETs, which are driven by the ATmega88 with following pins:

Red LED: Port B6

Green LED: Port C3

Blue LED: Port B7

Common: Port D3

That's all we need to know! Now let's make some light! We do this by simply turning the corresponding pins on or off. However, there's a catch: the LEDs don't have a current limiting resistor, so the current will only be limited by the internal resistance of the batteries. Not good. Furthermore, since the red LED has a lower forward voltage than the green and blue one, it will draw more current, and be a lot brighter than the other ones. Not good.

To nicely control the LEDs, we should control them with PWM. I did this by writing an interrupt routine which runs at 10 kHz and creates a PWM signal for all LEDs. It also compensates for the difference in current draw: the current duty cycle for the red LED is lower than the green and blue one. We can now control the brightness of each of the LEDs by updating a variable.

In the main loop, we'll do just that. I made some patterns which change the brightness of the LEDs. It should be quite easy to make some more for yourself, you can use my code as an example.

I've made more than 10 different patterns, and they just keep on looping. One loop takes around 5 minutes, so it won't get boring too quickly ;)