Skip to content

Commit

Permalink
Update machine.PWM.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
IhorNehrutsa committed Jul 20, 2023
1 parent efb17b6 commit 5d5dc3b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/library/machine.PWM.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Methods
With a single *value* argument the duty cycle is set to that value, measured
as the ratio ``value / 65535``.

Use functions like these to convert percentages to u16 and back::

def percents_to_u16(percents:int)->int:
return (percents * 2**16 + 50) // 100

def u16_to_percents(u16:int)->int:
return (u16 * 100 + 2**15) // 2**16

.. method:: PWM.duty_ns([value])

Get or set the current pulse width of the PWM output, as a value in nanoseconds.
Expand Down

0 comments on commit 5d5dc3b

Please sign in to comment.