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)
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
ring1:GND
ring1:VCC
ring1:DIN
ring1:DOUT