Merge branch 'master' of github.com:Microsoft/pxt-microbit

This commit is contained in:
Michal Moskal 2016-07-01 14:46:14 +01:00
commit 4ec6749ee6
3 changed files with 38 additions and 20 deletions

View File

@ -1,6 +1,8 @@
# Analog Set Period # Analog Set Period
Configures the period of the Pulse Width Modulation (PWM) on the specified analog [pin](/device/pins) (``P0``, ``P1`` or ``P2``). Prior to calling this function, the given pin should be set as analog. 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.
```sig ```sig
pins.analogSetPeriod(AnalogPin.P0, 20000) pins.analogSetPeriod(AnalogPin.P0, 20000)
@ -8,10 +10,11 @@ pins.analogSetPeriod(AnalogPin.P0, 20000)
### Parameters ### Parameters
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2") * `pin`: a [string](/reference/types/string) that specifies the pin to configure (`P0` through `P4`, or `P10`)
* `micros` - a [Number](/reference/types/number) representing the micro-seconds of the analog period. * `μs`: a [number](/reference/types/number) that specifies the analog period in microseconds.
The following code The following code first sets `P0` to analog with **analog write
pin**, and then sets the PWM period of `P0` to 20,000 microseconds.
```blocks ```blocks
pins.analogWritePin(AnalogPin.P0, 512) pins.analogWritePin(AnalogPin.P0, 512)
@ -20,5 +23,9 @@ pins.analogSetPeriod(AnalogPin.P0, 20000)
### See also ### See also
[micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin) [micro:bit pins](/device/pins),
[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)

View File

@ -1,8 +1,14 @@
# Map # Map
Re-maps a number from one range to another. That is, a value of ``from low`` would get mapped to ``to low``, a value of ``from high`` to ``to high``, values in-between to values in-between, etc. Remaps the specified value from one range to another. This function
maps the value of ``from low`` to the value of ``to low``, the value
of ``from high`` to the value of ``to high``, and intermediate values
to intermediate values.
Does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The `math->clamp` function may be used either before or after this function, if limits to the ranges are desired. This function does not constrain values to the ranges, because
out-of-range values are sometimes intended and useful. If you need to
limit a range, you can use the ``Math.clamp`` function before or after
calling this function.
```sig ```sig
pins.map(0, 0, 4, 0, 1023); pins.map(0, 0, 4, 0, 1023);
@ -10,15 +16,16 @@ pins.map(0, 0, 4, 0, 1023);
### Parameters ### Parameters
* ``value``: [Number](/reference/types/number) - the value to map * ``value``: a [number](/reference/types/number) that specifies the value to map
* ``from low``: [Number](/reference/types/number) - lower bound of the origin interval * ``from low``: a [number](/reference/types/number) that specifies the lower bound of the origin interval
* ``from high``: [Number](/reference/types/number) - upper bound of the origin interval * ``from high``: a [number](/reference/types/number) that specifies the upper bound of the origin interval
* ``to low``: [Number](/reference/types/number) - lower bound of the target interval * ``to low``: a [number](/reference/types/number) that specifies the lower bound of the target interval
* ``to high``: [Number](/reference/types/number) - upper bound of the target interval * ``to high``: a [number](/reference/types/number) that specifies the upper bound of the target interval
## Example ## Example
Map the value read from the analog pin ``P0`` to an LED index between ``0`` and ``4``. This example maps the value read from the analog pin `P0` to an LED
coordinate between `0` and `4`.
```blocks ```blocks
let value1 = pins.analogReadPin(AnalogPin.P0) let value1 = pins.analogReadPin(AnalogPin.P0)

View File

@ -1,6 +1,7 @@
# Servo Set Pulse # Servo Set Pulse
Configures the pin [pin](/device/pins) (``P0``, ``P1`` or ``P2``) as an analog/PWM output if it isn't already, configures the period to be 20ms, and sets the pulse width, based on the value it is given. Configure the specified pin as analog output, set the period to 20
ms, and set the pulse width to the specified value.
```sig ```sig
pins.servoSetPulse(AnalogPin.P1, 1500) pins.servoSetPulse(AnalogPin.P1, 1500)
@ -8,12 +9,12 @@ pins.servoSetPulse(AnalogPin.P1, 1500)
### Parameters ### Parameters
* `name` - [String](/reference/types/string); the pin name ("P0", "P1", or "P2") * `pin`: a [string](/reference/types/string) that specifies the pin to configure (`P0` through `P4`, or `P10`)
* `micros` - a [Number](/reference/types/number) representing the micro-seconds of the pulse width. * `μs`: a [number](/reference/types/number) that specifies the analog period in microseconds.
### Example ### Example
The following code sets the servo pulse to ``1000`` micro seconds. The following code sets the servo pulse to `1000` microseconds.
```blocks ```blocks
pins.servoSetPulse(AnalogPin.P0, 1000) pins.servoSetPulse(AnalogPin.P0, 1000)
@ -21,5 +22,8 @@ pins.servoSetPulse(AnalogPin.P0, 1000)
### See also ### See also
[BBC micro:bit pins](/device/pins), [on pin pressed](/reference/input/on-pin-pressed), [analog read pin](/reference/pins/analog-read-pin), [digital read pin](/reference/pins/digital-read-pin), [digital write pin](/reference/pins/digital-write-pin) [BBC micro:bit pins](/device/pins),
[on pin pressed](/reference/input/on-pin-pressed),
[analog read pin](/reference/pins/analog-read-pin),
[digital read pin](/reference/pins/digital-read-pin),
[digital write pin](/reference/pins/digital-write-pin)