midiOSCesp/esp/leds.py

65 lines
1.3 KiB
Python
Raw Normal View History

2021-01-06 02:48:09 +00:00
'''
test your strip. Change lednumber value
'''
2021-01-06 02:32:39 +00:00
import time
import machine, neopixel
lednumber = 8
np = neopixel.NeoPixel(machine.Pin(14), lednumber)
def demo(np):
n = np.n
# cycle
for i in range(4 * n):
for j in range(n):
np[j] = (0, 0, 0)
np[i % n] = (255, 255, 255)
np.write()
time.sleep_ms(25)
# bounce
for i in range(4 * n):
for j in range(n):
np[j] = (0, 0, 128)
if (i // n) % 2 == 0:
np[i % n] = (0, 0, 0)
else:
np[n - 1 - (i % n)] = (0, 0, 0)
np.write()
time.sleep_ms(60)
# fade in/out
for i in range(0, 4 * 256, 8):
for j in range(n):
if (i // 256) % 2 == 0:
val = i & 0xff
else:
val = 255 - (i & 0xff)
np[j] = (val, 0, 0)
np.write()
# clear
for i in range(n):
np[i] = (0, 0, 0)
np.write()
def npcolor(r, g, b):
for i in range(lednumber):
np[i] = (r, g, b)
np.write()
def npcycle():
for i in range(2 * lednumber):
for j in range(lednumber):
np[j] = (0, 0, 0)
np[i % lednumber] = (126, 20, 126)
np.write()
2021-01-16 18:57:46 +00:00
time.sleep_ms(15)
2021-01-06 02:32:39 +00:00
npcolor(0,0,0)
npcycle()
npcolor(0,0,0)
#demo(np)