pxt-calliope/docs/reference/pins/analog-set-period.md

32 lines
1.0 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# Analog Set Period
2016-06-30 20:02:28 +02:00
Configure the period of Pulse Width Modulation (PWM) on the specified
analog [pin](/device/pins).
Before you call this function, you should set the specified pin as analog.
2016-03-26 00:47:20 +01:00
```sig
pins.analogSetPeriod(AnalogPin.P0, 20000)
```
### Parameters
2016-07-19 00:51:28 +02:00
* ``name``: a [string](/reference/types/string) that specifies the pin to configure (`P0` through `P4`, or `P10`)
* ``micros``: a [number](/reference/types/number) that specifies the analog period in microseconds.
2016-03-26 00:47:20 +01:00
2016-06-30 20:02:28 +02:00
The following code first sets `P0` to analog with **analog write
pin**, and then sets the PWM period of `P0` to 20,000 microseconds.
2016-03-26 00:47:20 +01:00
```blocks
pins.analogWritePin(AnalogPin.P0, 512)
pins.analogSetPeriod(AnalogPin.P0, 20000)
```
### See also
2016-11-02 01:44:37 +01:00
[@boardname@ pins](/device/pins),
2016-06-30 20:02:28 +02:00
[on pin pressed](/reference/input/on-pin-pressed),
[analog read pin](/reference/pins/analog-read-pin),
[analog write pin](/reference/pins/analog-write-pin),
[digital read pin](/reference/pins/digital-read-pin),
[digital write pin](/reference/pins/digital-write-pin)