Add pwm examples

This commit is contained in:
Jimmy 2021-06-17 19:52:50 +12:00
parent de247b3354
commit d803fd81a5
2 changed files with 32 additions and 0 deletions

15
pwm/led.py Normal file
View File

@ -0,0 +1,15 @@
from machine import Pin
from machine import PWM
from time import sleep
led = PWM(Pin(0, Pin.OUT))
for i in range(-1, 1024, 8):
led.duty(i)
print(i)
sleep(0.1)
for i in range(1023, -1, -8):
led.duty(i)
print(i)
sleep(0.1)

17
pwm/rgb.py Normal file
View File

@ -0,0 +1,17 @@
from machine import Pin
from time import sleep
blue = Pin(0, Pin.OUT)
green = Pin(4, Pin.OUT)
red = Pin(5, Pin.OUT)
blue.off()
red.on()
sleep(1)
red.off()
green.on()
sleep(1)
green.off()
blue.on()
sleep(1)
blue.off()