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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.