Close

Controlling the LEDs from Micropython on the Supercon.8 Badge

A project log for Blinky Loop SAO

A small SAO with 12x WS2812 and an accelerometer

thomas-flummerThomas Flummer 11/01/2024 at 21:140 Comments

Simple micropython python snippet to control the LEDs on the Blinky Loop SAO

The neopixel library seems to be already on the micropython image on the badge, to no need to add a library.

This does a simple rainbow that rotates continuously. It's a little jumpy so there is room for improvement, but the code should be relatively simple to read.

from machine import Pin
import neopixel
import time

# setup Blinkyloop LEDs (pin 22 is GPIO1 on SAO port 4)
np = neopixel.NeoPixel(machine.Pin(22), 12)

def rainbow(np, brightness):
    n = np.n
    color_map = (255, 170, 128, 85, 0, 0, 0, 0, 0, 85, 128, 170)
    while True:
        for j in range(n):
            for i in range(n):
                r = color_map[i]
                g = color_map[((i + 4) % n)]
                b = color_map[((i + 8) % n)]
                np[((i + j) % n)] = (round(r * brightness), round(g * brightness), round(b * brightness))
            np.write()
            time.sleep_ms(50)

rainbow(np, 0.1)

Discussions