Thanks for you help. Just to double check, does the 0.02 (20mA) come from the difference between 40mA and 20mA. To look back at a specific section of the manual:
We therefore need to put in a resistor that will reduce the 5v to 2v and the current from 40mA to 20mA if we want to display the LED at it ʼ s maximum brightness.
The Voltage I use in my calculation is 3V (5V - 2V = 3V).
So does the current I use in my calculation 0.02A come from (0.04A - 0.02A = 0.02A) ?
Others have answered already but I wanted to make sure you are not confused. The 20mA comes from the specification of the diode. It has nothing to do with the 40mA limit of the pin. If the pin could output a maximum of 100mA, you would still be using the 20mA in the calculation as that is the current that will be going through the resistor and the diode. Is this clear?