From a63af1d04abba9de63f43054d1b5f9621f6c5407 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 28 Oct 2021 13:30:51 -0400 Subject: [PATCH] Update D13 to LED, add PWM example. --- docs/design_guide.rst | 4 ++-- shared-bindings/digitalio/__init__.c | 10 ++++---- shared-bindings/frequencyio/__init__.c | 6 ++--- shared-bindings/pulseio/PulseOut.c | 2 +- shared-bindings/pwmio/PWMOut.c | 24 +++++++++++++++---- shared-bindings/pwmio/__init__.c | 6 ++--- .../audiopwmio/wavefile_pause_resume.py | 1 - .../audiopwmio/wavefile_playback.py | 1 - 8 files changed, 34 insertions(+), 20 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 8c3c8cc842..fdb8f9b019 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -99,7 +99,7 @@ For example, a user can then use ``deinit()```:: import board import time - led = digitalio.DigitalInOut(board.D13) + led = digitalio.DigitalInOut(board.LED) led.direction = digitalio.Direction.OUTPUT for i in range(10): @@ -119,7 +119,7 @@ Alternatively, using a ``with`` statement ensures that the hardware is deinitial import board import time - with digitalio.DigitalInOut(board.D13) as led: + with digitalio.DigitalInOut(board.LED) as led: led.direction = digitalio.Direction.OUTPUT for i in range(10): diff --git a/shared-bindings/digitalio/__init__.c b/shared-bindings/digitalio/__init__.c index 39b569253b..e3f4e9992d 100644 --- a/shared-bindings/digitalio/__init__.c +++ b/shared-bindings/digitalio/__init__.c @@ -50,9 +50,9 @@ //| For example:: //| //| import digitalio -//| from board import * +//| import board //| -//| pin = digitalio.DigitalInOut(D13) +//| pin = digitalio.DigitalInOut(board.LED) //| print(pin.value) //| //| This example will initialize the the device, read @@ -61,11 +61,11 @@ //| //| Here is blinky:: //| -//| import digitalio -//| from board import * //| import time +//| import digitalio +//| import board //| -//| led = digitalio.DigitalInOut(D13) +//| led = digitalio.DigitalInOut(board.LED) //| led.direction = digitalio.Direction.OUTPUT //| while True: //| led.value = True diff --git a/shared-bindings/frequencyio/__init__.c b/shared-bindings/frequencyio/__init__.c index 02f19de65d..ffbb7af771 100644 --- a/shared-bindings/frequencyio/__init__.c +++ b/shared-bindings/frequencyio/__init__.c @@ -46,11 +46,11 @@ //| //| For example:: //| -//| import frequencyio //| import time -//| from board import * +//| import frequencyio +//| import board //| -//| frequency = frequencyio.FrequencyIn(D13) +//| frequency = frequencyio.FrequencyIn(board.D11) //| frequency.capture_period = 15 //| time.sleep(0.1) //| diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 90564fce89..bf2aaf54ff 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -59,7 +59,7 @@ //| import board //| //| # 50% duty cycle at 38kHz. -//| pwm = pulseio.PulseOut(board.D13, frequency=38000, duty_cycle=32768) +//| pwm = pulseio.PulseOut(board.LED, frequency=38000, duty_cycle=32768) //| # on off on off on //| pulses = array.array('H', [65000, 1000, 65000, 65000, 1000]) //| pulse.send(pulses) diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index e59605200a..1c0110653b 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -86,13 +86,29 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) { //| :param int frequency: The target frequency in Hertz (32-bit) //| :param bool variable_frequency: True if the frequency will change over time //| -//| Simple LED fade:: +//| +//| Simple LED on:: //| //| import pwmio //| import board //| -//| pwm = pwmio.PWMOut(board.D13) # output on D13 -//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz +//| pwm = pwmio.PWMOut(board.LED) +//| +//| while True: +//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz +//| +//| PWM LED fade:: +//| +//| import pwmio +//| import board +//| +//| pwm = pwmio.PWMOut(board.LED) # output on LED pin with default of 500Hz +//| +//| while True: +//| for cycle in range(0, 65535): # Cycles through the full PWM range from 0 to 65535 +//| pwm.duty_cycle = cycle # Cycles the LED pin duty cycle through the range of values +//| for cycle in range(65534, 0, -1): # Cycles through the PWM range backwards from 65534 to 0 +//| pwm.duty_cycle = cycle # Cycles the LED pin duty cycle through the range of values //| //| PWM at specific frequency (servos and motors):: //| @@ -100,7 +116,7 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) { //| import board //| //| pwm = pwmio.PWMOut(board.D13, frequency=50) -//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz +//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz //| //| Variable frequency (usually tones):: //| diff --git a/shared-bindings/pwmio/__init__.c b/shared-bindings/pwmio/__init__.c index 6c9e63a35f..c9f7a50155 100644 --- a/shared-bindings/pwmio/__init__.c +++ b/shared-bindings/pwmio/__init__.c @@ -45,11 +45,11 @@ //| //| For example:: //| -//| import pwmio //| import time -//| from board import * +//| import pwmio +//| import board //| -//| pwm = pwmio.PWMOut(D13) +//| pwm = pwmio.PWMOut(board.LED) //| pwm.duty_cycle = 2 ** 15 //| time.sleep(0.1) //| diff --git a/tests/circuitpython-manual/audiopwmio/wavefile_pause_resume.py b/tests/circuitpython-manual/audiopwmio/wavefile_pause_resume.py index 27912d3217..7b444aa997 100644 --- a/tests/circuitpython-manual/audiopwmio/wavefile_pause_resume.py +++ b/tests/circuitpython-manual/audiopwmio/wavefile_pause_resume.py @@ -3,7 +3,6 @@ import audiopwmio import board import digitalio import time -import math import os trigger = digitalio.DigitalInOut(board.D4) diff --git a/tests/circuitpython-manual/audiopwmio/wavefile_playback.py b/tests/circuitpython-manual/audiopwmio/wavefile_playback.py index 0adbf2b19c..a7de8c90ca 100644 --- a/tests/circuitpython-manual/audiopwmio/wavefile_playback.py +++ b/tests/circuitpython-manual/audiopwmio/wavefile_playback.py @@ -3,7 +3,6 @@ import audiopwmio import board import digitalio import time -import math import os trigger = digitalio.DigitalInOut(board.D4)