Add Docker deployment support, richer Selenium/LED pattern tests, in-browser diagnostics, responsive UI improvements, and 16x16 panel simulation tooling to speed iteration and hardware-style prototyping. Made-with: Cursor
1.4 KiB
1.4 KiB
Python LED Tutorial (NeoPixel Focus)
This tutorial is for the browser editor's ESP32-style mocks:
machine.Pinneopixel.NeoPixel
Use workspace/code/led_tutorial.py while reading this guide.
1) Basic setup
from machine import Pin
import neopixel
np = neopixel.NeoPixel(Pin(4), 12)
Pin(4)means data pin 4 (matching common ESP32 examples).12is the number of LEDs in the strip/ring.npis your LED strip object.
2) Set one LED color
np[0] = (255, 0, 0) # red
np.write()
- Colors are
(red, green, blue)from0to255. - Nothing updates visually until
np.write().
3) Fill all LEDs
np.fill((0, 0, 255)) # all blue
np.write()
4) Clear LEDs (turn off)
np.fill((0, 0, 0))
np.write()
5) Animate over time
import time
for step in range(20):
np.fill((step * 10, 0, 255 - step * 10))
np.write()
time.sleep(0.08)
time.sleep(...) controls animation speed.
6) Moving pixel example
for i in range(len(np)):
np.fill((0, 0, 0))
np[i] = (255, 120, 0)
np.write()
time.sleep(0.06)
7) Tips
- Keep color values in
0..255. - Use helper functions for repeated color logic.
- Start with short loops, then increase frames once behavior looks good.
- If the simulator is closed, run your script again to show updates.