WS2812B ESP32 micropython

WS2812B
 


ESP32 > WS2812B
3V3 > V+
 GND > V-
 D5 > IN



Матрица загорается красным , зеленым и синим.

main.py     


import machine
import neopixel
import time

# Number of LEDs in your chain:
NUM_LEDS = 64

# The pin you connect the data line to:
DATA_PIN = 5 # change to your pin

# Create the NeoPixel object
np = neopixel.NeoPixel(machine.Pin(DATA_PIN, machine.Pin.OUT), NUM_LEDS)

def clear():
for i in range(NUM_LEDS):
np[i] = (0, 0, 0)
np.write()

def set_color_all(r, g, b):
for i in range(NUM_LEDS):
np[i] = (r, g, b)
np.write()

def rainbow_cycle(delay_ms=20):
# A simple rainbow effect
for j in range(256):
for i in range(NUM_LEDS):
# wheel gives a color based on position
idx = (i * 256 // NUM_LEDS + j) & 255
np[i] = wheel(idx)
np.write()
time.sleep_ms(delay_ms)

def wheel(pos):
"""Generate colors across a 0-255 rainbow wheel."""
if pos < 85:
return (pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return (255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return (0, pos * 3, 255 - pos * 3)

# Demo loop
clear()
time.sleep(1)
set_color_all(50, 0, 0) # dim red
time.sleep(2)
set_color_all(0, 50, 0) # dim green
time.sleep(2)
set_color_all(0, 0, 50) # dim blue
time.sleep(2)
rainbow_cycle(10)


while True:
rainbow_cycle(50)





Комментарии

Популярные сообщения из этого блога

Установка micropython на ESP32

LORA Приемник и передатчик

LORA Upgrade E32 400M30S