Migrate docs from the other repo
This commit is contained in:
31
docs/reference/pins/analog-pitch.md
Normal file
31
docs/reference/pins/analog-pitch.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Analog Pitch
|
||||
|
||||
Emits a Pulse With Modulation (PWM) signal to the current pitch [pin](/microbit/device/pins). Use [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin) to set the pitch pin.
|
||||
|
||||
```sig
|
||||
pins.analogPitch(440, 300)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `frequency` : [Number](/microbit/reference/types/number)
|
||||
* `ms`: [Number](/microbit/reference/types/number)
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
pins.analogSetPitchPin("P0")
|
||||
let frequency1 = 440
|
||||
let duration = 1000
|
||||
pins.analogPitch(frequency1, duration)
|
||||
```
|
||||
|
||||
### Some common notes
|
||||
|
||||
* 440 = A4 on piano
|
||||
* see [piano key frequencies ](https://en.wikipedia.org/wiki/Piano_key_frequencies) for more information
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [analog set period](/microbit/reference/pins/analog-set-period), [analog set pitch pin](/microbit/reference/pins/analog-set-pitch-pin)
|
||||
|
29
docs/reference/pins/analog-read-pin.md
Normal file
29
docs/reference/pins/analog-read-pin.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Analog Read Pin
|
||||
|
||||
Read the specified [pin](/microbit/device/pins) (P0, P1, P2) as analog.
|
||||
|
||||
```sig
|
||||
pins.analogReadPin(AnalogPin.P0)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* name - the pin name (`P0`, `P1`, or `P2`)
|
||||
|
||||
### Returns
|
||||
|
||||
* [Number](/microbit/reference/types/number) - a number between 0 and 1023 (included)
|
||||
|
||||
The following code reads `P1` and charts it on the screen:
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let value = pins.analogReadPin(AnalogPin.P1)
|
||||
led.plotBarGraph(value, 1023)
|
||||
});
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog write pin](/microbit/reference/pins/analog-write-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
|
24
docs/reference/pins/analog-set-period.md
Normal file
24
docs/reference/pins/analog-set-period.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Analog Set Period
|
||||
|
||||
Configures the period of the Pulse Width Modulation (PWM) on the specified analog [pin](/microbit/device/pins) (``P0``, ``P1`` or ``P2``). Prior to calling this function, the given pin should be set as analog.
|
||||
|
||||
```sig
|
||||
pins.analogSetPeriod(AnalogPin.P0, 20000)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `micros` - a [Number](/microbit/reference/types/number) representing the micro-seconds of the analog period.
|
||||
|
||||
The following code
|
||||
|
||||
```blocks
|
||||
pins.analogWritePin(AnalogPin.P0, 512)
|
||||
pins.analogSetPeriod(AnalogPin.P0, 20000)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
|
30
docs/reference/pins/analog-set-pitch-pin.md
Normal file
30
docs/reference/pins/analog-set-pitch-pin.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Analog Set Pitch Pin
|
||||
|
||||
Specify which [pin](/microbit/device/pins) (P0, P1, P2) is used to generate tones.
|
||||
|
||||
```sig
|
||||
pins.analogSetPitchPin(AnalogPin.P0)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
pins.analogSetPitchPin(AnalogPin.P0)
|
||||
let frequency = 440
|
||||
let duration = 1000
|
||||
pins.analogPitch(frequency, duration)
|
||||
```
|
||||
|
||||
### Some common notes
|
||||
|
||||
* 440 = A4 on piano
|
||||
* see [piano key frequencies ](https://en.wikipedia.org/wiki/Piano_key_frequencies) for more information
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [analog set period](/microbit/reference/pins/analog-set-period), [analog pitch](/microbit/reference/pins/analog-pitch)
|
||||
|
23
docs/reference/pins/analog-write-pin.md
Normal file
23
docs/reference/pins/analog-write-pin.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Analog Write Pin
|
||||
|
||||
Write to the specified [pin](/microbit/device/pins) (P0, P1, P2) as analog.
|
||||
|
||||
```sig
|
||||
pins.analogWritePin(AnalogPin.P0, 400)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `value` - a [Number](/microbit/reference/types/number) between 0 and 1023 included
|
||||
|
||||
The following code writes `1023` to the `P0` pin:
|
||||
|
||||
```blocks
|
||||
pins.analogWritePin(AnalogPin.P0, 1023)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
|
40
docs/reference/pins/digital-read-pin.md
Normal file
40
docs/reference/pins/digital-read-pin.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Digital Read Pin
|
||||
|
||||
The digital read pin function. #digitalreadpin #docs
|
||||
|
||||
Digitally read the specified [pin](/microbit/device/pins) (``P0``, ``P1``, ``P2``, ...) as digital. **Some pins are also used by the display, read the [pin documentation ](/microbit/device/pins) carefully.**
|
||||
|
||||
```sig
|
||||
pins.digitalReadPin(DigitalPin.P3)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* name - the pin name ``P0``, ``P1``, ``P2``, ...
|
||||
|
||||
### Returns
|
||||
|
||||
* [Number](/microbit/reference/types/number) - 0 or 1
|
||||
|
||||
### Example: football score keeper
|
||||
|
||||
The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound:
|
||||
|
||||
```blocks
|
||||
let score = 0
|
||||
basic.showNumber(score)
|
||||
basic.forever(() => {
|
||||
if (pins.digitalReadPin(DigitalPin.P0) == 1) {
|
||||
score++;
|
||||
pins.digitalWritePin(DigitalPin.P2, 1)
|
||||
basic.showNumber(score)
|
||||
basic.pause(1000)
|
||||
pins.digitalWritePin(DigitalPin.P2, 0)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [digital write pin](/microbit/reference/pins/digital-write-pin), [analog read pin](/microbit/reference/pins/analog-read-pin), [analog write pin](/microbit/reference/pins/analog-write-pin), [on pin pressed](/microbit/reference/input/on-pin-pressed), [pin is pressed](/microbit/reference/input/pin-is-pressed)
|
||||
|
35
docs/reference/pins/digital-write-pin.md
Normal file
35
docs/reference/pins/digital-write-pin.md
Normal file
@ -0,0 +1,35 @@
|
||||
# Digital Write Pin
|
||||
|
||||
Write the value ``0`` or ``1`` to the specified (digital) [pin](/microbit/device/pins). **Some pins are also used by the display, read the [pin documentation ](/microbit/device/pins) carefully.**
|
||||
|
||||
```sig
|
||||
pins.digitalWritePin(DigitalPin.P1, 1)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* name - the pin name (``P0``, ``P1``, ``P2``, ...)
|
||||
* value - [Number](/microbit/reference/types/number); 0 or 1
|
||||
|
||||
### Example: football score keeper
|
||||
|
||||
The following example reads `P0` to determine when a goal is scored. When `P0 = 1`, the code uses `digital write pin` to play a buzzer sound:
|
||||
|
||||
```blocks
|
||||
let score = 0
|
||||
basic.showNumber(score)
|
||||
basic.forever(() => {
|
||||
if (pins.digitalReadPin(DigitalPin.P0) == 1) {
|
||||
score++;
|
||||
pins.digitalWritePin(DigitalPin.P2, 1)
|
||||
basic.showNumber(score)
|
||||
basic.pause(1000)
|
||||
pins.digitalWritePin(DigitalPin.P2, 0)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[micro:bit pins](/microbit/device/pins), [digital read pin](/microbit/reference/pins/digital-read-pin), [analog read pin](/microbit/reference/pins/analog-read-pin), [analog write pin](/microbit/reference/pins/analog-write-pin), [on pin pressed](/microbit/reference/input/on-pin-pressed), [pin is pressed](/microbit/reference/pins/pin-is-pressed)
|
||||
|
32
docs/reference/pins/map.md
Normal file
32
docs/reference/pins/map.md
Normal file
@ -0,0 +1,32 @@
|
||||
# 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.
|
||||
|
||||
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.
|
||||
|
||||
```sig
|
||||
pins.map(0, 0, 4, 0, 1023);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* ``value``: [Number](/microbit/reference/types/number) - the value to map
|
||||
* ``from low``: [Number](/microbit/reference/types/number) - lower bound of the origin interval
|
||||
* ``from high``: [Number](/microbit/reference/types/number) - upper bound of the origin interval
|
||||
* ``to low``: [Number](/microbit/reference/types/number) - lower bound of the target interval
|
||||
* ``to high``: [Number](/microbit/reference/types/number) - upper bound of the target interval
|
||||
|
||||
## Example
|
||||
|
||||
Map the value read from the analog pin ``P0`` to an LED index between ``0`` and ``4``.
|
||||
|
||||
```blocks
|
||||
let value1 = pins.analogReadPin(AnalogPin.P0)
|
||||
let index = pins.map(value1, 0, 1023, 0, 4)
|
||||
led.plot(0, index)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[analog read pin](/microbit/reference/pins/analog-read-pin)
|
||||
|
25
docs/reference/pins/servo-set-pulse.md
Normal file
25
docs/reference/pins/servo-set-pulse.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Servo Set Pulse
|
||||
|
||||
Configures the pin [pin](/microbit/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.
|
||||
|
||||
```sig
|
||||
pins.servoSetPulse(AnalogPin.P1, 1500)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `micros` - a [Number](/microbit/reference/types/number) representing the micro-seconds of the pulse width.
|
||||
|
||||
### Example
|
||||
|
||||
The following code sets the servo pulse to ``1000`` micro seconds.
|
||||
|
||||
```blocks
|
||||
pins.servoSetPulse(AnalogPin.P0, 1000)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/microbit/device/pins), [on pin pressed](/microbit/reference/input/on-pin-pressed), [analog read pin](/microbit/reference/pins/analog-read-pin), [digital read pin](/microbit/reference/pins/digital-read-pin), [digital write pin](/microbit/reference/pins/digital-write-pin)
|
||||
|
45
docs/reference/pins/servo-write-pin.md
Normal file
45
docs/reference/pins/servo-write-pin.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Servo Write Pin
|
||||
|
||||
Writes a value to the servo on to the specified [pin](/microbit/device/pins) (``P0``, ``P1``, ``P2``), controlling the shaft accordingly.
|
||||
|
||||
* on a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation.
|
||||
* on a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).
|
||||
|
||||
```sig
|
||||
pins.servoWritePin(AnalogPin.P0, 180)
|
||||
```
|
||||
|
||||
### Parameters
|
||||
|
||||
* `name` - [String](/microbit/reference/types/string); the pin name ("P0", "P1", or "P2")
|
||||
* `value` - a [Number](/microbit/reference/types/number) between 0 and 180 included
|
||||
|
||||
### Examples
|
||||
|
||||
* setting the shaft angle to mid point on a servo
|
||||
|
||||
```blocks
|
||||
pins.servoWritePin(AnalogPin.P0, 90)
|
||||
```
|
||||
|
||||
* control the shaft by using the tilt information of the accelerometer
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
let millig = input.acceleration(Dimensions.X)
|
||||
// map accelerometer readings to angle
|
||||
let angle = pins.map(millig, -1023, 1023, 0, 180)
|
||||
pins.servoWritePin(AnalogPin.P0, angle)
|
||||
})
|
||||
```
|
||||
|
||||
* setting the full speed on a continuous servo
|
||||
|
||||
```blocks
|
||||
pins.servoWritePin(AnalogPin.P0, 0)
|
||||
```
|
||||
|
||||
### See also
|
||||
|
||||
[BBC micro:bit pins](/microbit/device/pins), [servo set pulse](/microbit/reference/pins/servo-set-pulse)
|
||||
|
Reference in New Issue
Block a user