Demo showing bottom LED fading to different color on button press.
Demo showing top two LEDs’ fading duration changing based on duration of their respective button press duration.
Circuit drawing
The circuit is is powered via USB connected to the Arudino microcontroller. The blue LEDs at the top are connected to pin 6 and 5 respectively. Each primary color LED that made up the RGB LED is connected to pin 9, 10, 11 for red, green, and blue. Each LED is connected in series with a resistor to reduce the current through the LED.
The circuit also contains 3 push buttons connected to pin 8, 4, and 2. A 10 kΩ resister is connected in parallel to the digital input pins to prevent a short circuit and ensure consisitency when reading from those digital pins.
Calculating resistor values
Because each LED used in this assignment can operate safely with $\leq 30 \text{mA}$ of current, we need to use resisters to reduce the amount of current going through each LED.
Since we are connecting the resister & the LED in series, the amount of current through the LED is the same as that for the resister ($I_\text{L} = I_\text{r}$). This also means that the sum of voltage drop across the resister and LED should be equal to the voltage provided by the Arduino microcontroller (5V).
With these information, we calculate the minimum resistance by applying Ohm’s law on the resister.
$$
\begin{align*}
V_\text{r} &= I_\text{r} R_\text{r} && \text{Ohm’s law}\cr
V_\text{PSU} - V_\text{L} &= I_\text{L} R_\text{r} &&\text{Substitute resister V & I}\cr
5\texttt{V} - V_\text{L} &= 20\texttt{mA} \cdot R_\text{r}\cr
\end{align*}
$$
A 220 Ω resister is used for red and green LEDs because these LEDs have a voltage drop of 1.7V. Their resisters’ resistance to be at least
$$
\begin{align*}
V&=IR\cr
5\;\texttt{V} - 1.7\;\texttt{V} &=20\;\texttt{mA} \cdot \textrm{R}\cr
\frac{3.3\;\texttt{V}}{0.02\;\texttt{A}} &= \textrm{R}\cr
\textrm{R} &= 165 \;\Omega
\end{align*}
$$
A 220 Ω resister is used for the blue LED (voltage drop = 3.3V). It needs an resistor that is at least
$$
\begin{align*}
V&=IR\cr
5\;\texttt{V} - 3.3\;\texttt{V} &=20\;\texttt{mA} \cdot \textrm{R}\cr
\frac{1.7\;\texttt{V}}{0.02\;\texttt{A}} &= \textrm{R}\cr
\textrm{R} &= 85 \;\Omega
\end{align*}
$$
Using a resistor with higher resistance than what is required here (e.g. a 100 Ω resistor) will not have an adverse effect on the longevity of the LED, it will simply cause it to appear a bit dimmer.