First of all a few theory

Bi-colour leds.

A bi-colour LED has two LEDs wired in 'inverse parallel' (one forwards, one backwards) combined in one package with two leads. Only one of the LEDs can be lit at one time.

PWM

Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a commonly used technique for controlling power to inertial electrical devices, made practical by modern electronic power switches.

The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is.

The PWM switching frequency has to be much faster than what would affect the load, which is to say the device that uses the power. Typically switchings have to be done several times a minute in an electric stove, 120 Hz in a lamp dimmer, from few kilohertz (kHz) to tens of kHz for a motor drive and well into the tens or hundreds of kHz in audio amplifiers and computer power supplies.

The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.

The main advantage of PWM is that power loss in the switching devices is very low. When a switch is off there is practically no current, and when it is on, there is almost no voltage drop across the switch. Power loss, being the product of voltage and current, is thus in both cases close to zero. PWM also works well with digital controls, which, because of their on/off nature, can easily set the needed duty cycle.

For this tutorial you need the following parts:

A bi-color led

An Arduino UNO (or other) board

Connections

Connect the central pin of your bicolor led to the Arduino GND pin.

Connect the red pin of the biclor led to Arduino pin 11.

Connect the green pin of the bicolor led to Arduino pin 10.

That's all

The Software

The software works as follow:

It sets the pin 10 and the pin 11 in output mode, then for each one of the pins run two loops, the first one writes (using the analogWrite function) on the pin values from 0 to 255 with steps of 5, every 20 ms. The second loop writes (using the analogWrite function) on the pin values from 255 to 0 with steps of -5, every 20 ms.

There isn't anymore to say.

Here you are the code