8000 WIP docs: Add machine.PWM by mcauser · Pull Request #2283 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

WIP docs: Add machine.PWM #2283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/library/machine.PWM.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.. currentmodule:: machine
.. _machine.PWM:

class PWM -- pulse width modulation
======================================

PWM can be enabled on all pins except Pin(16). There is a single frequency
for all channels, with range between 1 and 1000 (measured in Hz). The duty
cycle is between 0 and 1023 inclusive.

Example usage::

from machine import Pin, PWM

pwm0 = PWM(Pin(0)) # create PWM object from a pin
pwm0.freq() # get current frequency
pwm0.freq(1000) # set frequency
pwm0.duty() # get current duty cycle
pwm0.duty(200) # set duty cycle
pwm0.deinit() # turn off PWM on the pin

pwm2 = PWM(Pin(2), freq=500, duty=512) # create and configure in one go

Constructors
------------

.. class:: PWM(pin,... )

Create a PWM object. See ``init()`` for parameters if initialization.

Methods
-------

.. method:: PWM.init(pin, freq, duty)

Create a PWM object from a pin.

.. method:: PWM.deinit()

Disable PWM on the pin.

.. method:: PWM.freq()

Get or set the frequency (in Hz).

.. method:: PWM.duty()

Get or set the duty cycle of the PWM signal.
1 change: 1 addition & 0 deletions docs/library/machine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ Classes
machine.ADC.rst
machine.I2C.rst
machine.Pin.rst
machine.PWM.rst
machine.RTC.rst
machine.SD.rst
machine.SPI.rst
Expand Down
0