Required Components


About RGBLED


RGBLED Electronic Circuit

When checking the datasheet, the VF values of G and B are 3.6V, while the VF value of R is only 2V. When no resistor is used, the current values of G and B are 10mA, and R is 27mA. To set the current value to 10mA, according to Ohm's law:
R = V / I = (3.3 - 2) / 0.01 = 130Ω
Although this results in 130Ω, in practice there is a range in VF values, and the datasheet also indicates that when IF is 20mA, VF is between 2~2.5V, so the resistor value can be around this range without any issues. Despite the various considerations, we will use 56Ω in this tutorial.
Circuit Diagram

Breadboard Circuit


Program

A program that cycles through red⇒magenta⇒blue at 1-second intervals

LEDR = 15
LEDG = 16
LEDB = 17
pinMode(LEDR, 0)
pinMode(LEDG, 0)
pinMode(LEDB, 0)
while  true
  digitalWrite(LEDR, 1)
  sleep(1)
  digitalWrite(LEDB, 1)
  sleep(1)
  digitalWrite(LEDR, 0)
  sleep(1)
  digitalWrite(LEDB, 0)
end
To set the pin behavior, use pinMode(pin number, setting value). The setting value is 0 for output mode (LED, etc.), and 1 for input mode (switch, etc.).

Task: