Skip to content

Commit fd85ebf

Browse files
authored
Merge pull request #5523 from kattni/led-docs-update
Update D13 to LED, add PWM example.
2 parents a8b69f2 + a63af1d commit fd85ebf

File tree

8 files changed

+34
-20
lines changed

8 files changed

+34
-20
lines changed

docs/design_guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ For example, a user can then use ``deinit()```::
9999
import board
100100
import time
101101

102-
led = digitalio.DigitalInOut(board.D13)
102+
led = digitalio.DigitalInOut(board.LED)
103103
led.direction = digitalio.Direction.OUTPUT
104104

105105
for i in range(10):
@@ -119,7 +119,7 @@ Alternatively, using a ``with`` statement ensures that the hardware is deinitial
119119
import board
120120
import time
121121

122-
with digitalio.DigitalInOut(board.D13) as led:
122+
with digitalio.DigitalInOut(board.LED) as led:
123123
led.direction = digitalio.Direction.OUTPUT
124124

125125
for i in range(10):

shared-bindings/digitalio/__init__.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
//| For example::
5151
//|
5252
//| import digitalio
53-
//| from board import *
53+
//| import board
5454
//|
55-
//| pin = digitalio.DigitalInOut(D13)
55+
//| pin = digitalio.DigitalInOut(board.LED)
5656
//| print(pin.value)
5757
//|
5858
//| This example will initialize the the device, read
@@ -61,11 +61,11 @@
6161
//|
6262
//| Here is blinky::
6363
//|
64-
//| import digitalio
65-
//| from board import *
6664
//| import time
65+
//| import digitalio
66+
//| import board
6767
//|
68-
//| led = digitalio.DigitalInOut(D13)
68+
//| led = digitalio.DigitalInOut(board.LED)
6969
//| led.direction = digitalio.Direction.OUTPUT
7070
//| while True:
7171
//| led.value = True

shared-bindings/frequencyio/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646
//|
4747
//| For example::
4848
//|
49-
//| import frequencyio
5049
//| import time
51-
//| from board import *
50+
//| import frequencyio
51+
//| import board
5252
//|
53-
//| frequency = frequencyio.FrequencyIn(D13)
53+
//| frequency = frequencyio.FrequencyIn(board.D11)
5454
//| frequency.capture_period = 15
5555
//| time.sleep(0.1)
5656
//|

shared-bindings/pulseio/PulseOut.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//| import board
6060
//|
6161
//| # 50% duty cycle at 38kHz.
62-
//| pwm = pulseio.PulseOut(board.D13, frequency=38000, duty_cycle=32768)
62+
//| pwm = pulseio.PulseOut(board.LED, frequency=38000, duty_cycle=32768)
6363
//| # on off on off on
6464
//| pulses = array.array('H', [65000, 1000, 65000, 65000, 1000])
6565
//| pulse.send(pulses)

shared-bindings/pwmio/PWMOut.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,37 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) {
8686
//| :param int frequency: The target frequency in Hertz (32-bit)
8787
//| :param bool variable_frequency: True if the frequency will change over time
8888
//|
89-
//| Simple LED fade::
89+
//|
90+
//| Simple LED on::
91+
//|
92+
//| import pwmio
93+
//| import board
94+
//|
95+
//| pwm = pwmio.PWMOut(board.LED)
96+
//|
97+
//| while True:
98+
//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz
99+
//|
100+
//| PWM LED fade::
90101
//|
91102
//| import pwmio
92103
//| import board
93104
//|
94-
//| pwm = pwmio.PWMOut(board.D13) # output on D13
95-
//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz
105+
//| pwm = pwmio.PWMOut(board.LED) # output on LED pin with default of 500Hz
106+
//|
107+
//| while True:
108+
//| for cycle in range(0, 65535): # Cycles through the full PWM range from 0 to 65535
109+
//| pwm.duty_cycle = cycle # Cycles the LED pin duty cycle through the range of values
110+
//| for cycle in range(65534, 0, -1): # Cycles through the PWM range backwards from 65534 to 0
111+
//| pwm.duty_cycle = cycle # Cycles the LED pin duty cycle through the range of values
96112
//|
97113
//| PWM at specific frequency (servos and motors)::
98114
//|
99115
//| import pwmio
100116
//| import board
101117
//|
102118
//| pwm = pwmio.PWMOut(board.D13, frequency=50)
103-
//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz
119+
//| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz
104120
//|
105121
//| Variable frequency (usually tones)::
106122
//|

shared-bindings/pwmio/__init__.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
//|
4646
//| For example::
4747
//|
48-
//| import pwmio
4948
//| import time
50-
//| from board import *
49+
//| import pwmio
50+
//| import board
5151
//|
52-
//| pwm = pwmio.PWMOut(D13)
52+
//| pwm = pwmio.PWMOut(board.LED)
5353
//| pwm.duty_cycle = 2 ** 15
5454
//| time.sleep(0.1)
5555
//|

tests/circuitpython-manual/audiopwmio/wavefile_pause_resume.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import board
44
import digitalio
55
import time
6-
import math
76
import os
87

98
trigger = digitalio.DigitalInOut(board.D4)

tests/circuitpython-manual/audiopwmio/wavefile_playback.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import board
44
import digitalio
55
import time
6-
import math
76
import os
87

98
trigger = digitalio.DigitalInOut(board.D4)

0 commit comments

Comments
 (0)