pb pbaumgarten.com
Courses Python Reference Neopixels
Login
Course
Python Reference
Topic
MicroPython
Python Reference

Neopixels

Using the MicroPython Neopixel library

import machine
import neopixel
import time

led = neopixel.NeoPixel(machine.Pin(48), 1)
print("Police lights!")
while True:
    led[0] = (255,0,0)
    led.write()
    time.sleep(0.25)
    led[0] = (0,0,255)
    led.write()
    time.sleep(0.25)

There is also a .fill() method available to set all LEDs to a single color.

Colour examples:

Colour RGB tuple
Red (255, 0, 0)
Green (0, 255, 0)
Blue (0, 0, 255)
Yellow (255, 255, 0)
Cyan (0, 255, 255)
Magenta (255, 0, 255)
White (255, 255, 255)
Off (0, 0, 0)