pinGPT logo
Chapter C: RGB LED4/8
Chapter B

Chapter C

Play with the Onboard Multicolor LED 🌈

Write and run your very first MicroPython program. Discover your first interactions with the board through the onboard RGB LED and buttons.

[ The onboard RGB LED glowing red, green, then blue ]

1. Meet the onboard RGB LED

Your pinGPT has a single multicolor LED soldered to the board, wired to GPIO 48. It's a tiny NeoPixel — one LED that can shine in any color you want.

2. Cycle through colors

Open Thonny, paste this program, and press Run:

python
from machine import Pin
from neopixel import NeoPixel
from time import sleep

# The onboard RGB LED is wired to GPIO 48
np = NeoPixel(Pin(48, Pin.OUT), 1)

while True:
    np[0] = (255, 0, 0)   # red
    np.write(); sleep(0.5)
    np[0] = (0, 255, 0)   # green
    np.write(); sleep(0.5)
    np[0] = (0, 0, 255)   # blue
    np.write(); sleep(0.5)

The LED should now cycle through red, green, and blue. You just spoke to hardware in real time.

3. Read the onboard button

pinGPT also has a built-in button on GPIO 0. Let's make the LED change color when you press it:

python
from machine import Pin
from neopixel import NeoPixel

button = Pin(0, Pin.IN, Pin.PULL_UP)
np = NeoPixel(Pin(48, Pin.OUT), 1)

while True:
    if button.value() == 0:        # pressed
        np[0] = (0, 255, 0)        # green
    else:
        np[0] = (50, 0, 50)        # purple idle
    np.write()
[ Pressing the onboard button turns the LED green ]

What just happened

You used outputs (the RGB LED) and inputs (the button) at the same time — the two building blocks of every interactive electronics project. Stop the program any time with Ctrl + C.