from machine import Pin
from neopixel import NeoPixel
from time import sleep
import random
# pin = Pin(13, Pin.OUT) # GPIO13
pin = Pin(23, Pin.OUT) # GPIO23
np = NeoPixel(pin, 16) # NeoPixel Ring 16
ring = [0 for _ in range(16)]
direction = random.choice(['left', 'right'])
x = 4
def step():
global x
global direction
if direction == 'left':
x = max(0, x - 1)
if x == 0:
direction = 'right'
elif direction == 'right':
x = min(15, x + 1)
if x == 15:
direction = 'left'
for i in range(16):
ring[i] = max(0, ring[i] - 10) # Fade out all positions
ring[x] = 100 # Mark the new position
def paint():
for i in range(16):
value = ring[i]
np[i] = (0, value, 0)
np.write() # Update the LED strip
def walk(steps):
for _ in range(steps):
step()
paint()
sleep(0.2)
walk(256)