From d803fd81a58358522052e055e4f8d2d06dbb13f8 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 17 Jun 2021 19:52:50 +1200 Subject: [PATCH] Add pwm examples --- pwm/led.py | 15 +++++++++++++++ pwm/rgb.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 pwm/led.py create mode 100644 pwm/rgb.py diff --git a/pwm/led.py b/pwm/led.py new file mode 100644 index 0000000..3f9aee3 --- /dev/null +++ b/pwm/led.py @@ -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) diff --git a/pwm/rgb.py b/pwm/rgb.py new file mode 100644 index 0000000..ee870bb --- /dev/null +++ b/pwm/rgb.py @@ -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() \ No newline at end of file