I'm just trying my first steps with micropython on an ESP8266. I have a little experience with the Arduino language.
As a first task I would like to program a running light made of 7 LEDs. The structure is on a breadboard
and works because I can individually turn each LED on, off and using PWM.
As soon as I want to switch the LED on and off one after the other via a loop, the running light always stops briefly.
I recorded a video to show it: https://streamable.com/0wwsn2
The code is very simple:
Code: Select all
import time, math
from machine import Pin, PWM
import esp
esp.osdebug(1)
leds = list( PWM(Pin(i), freq=80, duty=0) for i in [0, 15, 13, 12, 14, 4, 5])
#leds[2].duty(1000)
for j in range(100):
leds.reverse()
for led in leds:
led.duty(1023)
print(led)
time.sleep_ms(100)
led.duty(0)
I tried different PWM frequencies and found that the effect is less when the frequency is significantly lower (100Hz).
I'm using a NodeMCU with the current Python version 1.13.
I have Thonny and µPyCraft as software under Windows 10.
My questions are: am I making a mistake?
Am I still thinking too much in Arduino?
How is the right way in micropython?
Kind regards
Kolja