Need help with a script
Posted: Sun Nov 14, 2021 6:22 pm
Hello,
I'm from from France (I didn't really find a forum in French so here I am)
I have an ESP32 and ws2812 led, I'd like to create a fade in/out effect with the color I want. I started a code but it doesn't work also I'm a big beginner in coding. Here is my code :
Help would be much appreciated.
Thanks.
I'm from from France (I didn't really find a forum in French so here I am)
I have an ESP32 and ws2812 led, I'd like to create a fade in/out effect with the color I want. I started a code but it doesn't work also I'm a big beginner in coding. Here is my code :
Code: Select all
import machine, time, neopixel
n = 5 #number of led
p = 13 #Pin number on the board
freq = 5000 #frequency
np = neopixel.NeoPixel(machine.Pin(p), n) #neopixel object
led = machine.PWM(machine.Pin(p), freq) #PWM object
while True:
#color rgb
r = 103
g = 202
b = 232
for i in range(n):
np[i] = (r, g, b)
np.write()
for duty_cycle in range(0, 1024, 10):
led.duty(duty_cycle)
time.sleep(0.05)
for duty_cycle in range(1024, 0, -10):
led.duty(duty_cycle)
time.sleep(0.05)
Thanks.