import neopixel,machine
# pin is a machine.Pin instance.
# n is the number of LEDs in the strip.
# bpp is 3 for RGB LEDs, and 4 for RGBW LEDs.
# timing is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz).
np = neopixel.NeoPixel(machine.Pin(4),16,bpp=3,timing=1)
#np[0] = (255, 0, 0) # set to red, full brightness
# np[1] = (0, 128, 0) # set to green, half brightness
#blue = (0, 0, 64) # set to blue, quarter brightne
# it fills the extire led's to a given tuple colour
#np.fill((23,23,233))
#np.write()
#to get the length of the pixel (count)
#np.__len__()
#
# for i in range(16):
# np.__setitem__(i, (2,110,4))
# np.write()
#
import time
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, 18)
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()
demo(np)