NodeMCU Projects: Difference between revisions
Content added Content deleted
(→Basics) |
|||
Line 88: | Line 88: | ||
toggle(pin) |
toggle(pin) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
*Fading an LED |
|||
<syntaxhighlight lang="python"> |
|||
led = machine.PWM(machine.Pin(2), freq=1000) |
|||
import time, math |
|||
def pulse(l, t): |
|||
for i in range(20): |
|||
l.duty(int(math.sin(i / 10 * math.pi) * 500 + 500)) |
|||
time.sleep_ms(t) |
|||
while True: |
|||
pulse(led, 20) |
|||
</syntaxhighlight> |
|||