summaryrefslogtreecommitdiff
path: root/examples/hwapi/soft_pwm.py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-02-27 22:03:52 -0500
committerGitHub <noreply@github.com>2018-02-27 22:03:52 -0500
commit568c04e6afa8016062f685b2198c0209f62827f4 (patch)
treed07b76119f715add462983b335797adf64b61249 /examples/hwapi/soft_pwm.py
parent6a2379fd0bfe10017d8abc5c36ef1d470c0d9b27 (diff)
parentea633117d01d94e8d56ed94344e4b3e46b4eef03 (diff)
Merge pull request #650 from tannewt/merge_2x3.0.0-alpha.2
Merge in commits from 2.x branch.
Diffstat (limited to 'examples/hwapi/soft_pwm.py')
-rw-r--r--examples/hwapi/soft_pwm.py38
1 files changed, 0 insertions, 38 deletions
diff --git a/examples/hwapi/soft_pwm.py b/examples/hwapi/soft_pwm.py
deleted file mode 100644
index 72291b0ec..000000000
--- a/examples/hwapi/soft_pwm.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import utime
-from hwconfig import LED
-
-
-# Using sleep_ms() gives pretty poor PWM resolution and
-# brightness control, but we use it in the attempt to
-# make this demo portable to even more boards (e.g. to
-# those which don't provide sleep_us(), or provide, but
-# it's not precise, like would be on non realtime OSes).
-# We otherwise use 20ms period, to make frequency not less
-# than 50Hz to avoid visible flickering (you may still see
-# if you're unlucky).
-def pwm_cycle(led, duty, cycles):
- duty_off = 20 - duty
- for i in range(cycles):
- if duty:
- led.on()
- utime.sleep_ms(duty)
- if duty_off:
- led.off()
- utime.sleep_ms(duty_off)
-
-
-# At the duty setting of 1, an LED is still pretty bright, then
-# at duty 0, it's off. This makes rather unsmooth transition, and
-# breaks fade effect. So, we avoid value of 0 and oscillate between
-# 1 and 20. Actually, highest values like 19 and 20 are also
-# barely distinguishible (like, both of them too bright and burn
-# your eye). So, improvement to the visible effect would be to use
-# more steps (at least 10x), and then higher frequency, and use
-# range which includes 1 but excludes values at the top.
-while True:
- # Fade in
- for i in range(1, 21):
- pwm_cycle(LED, i, 2)
- # Fade out
- for i in range(20, 0, -1):
- pwm_cycle(LED, i, 2)