2016-03-26 00:47:20 +01:00
|
|
|
# Analog Read Pin
|
|
|
|
|
2016-06-23 01:24:14 +02:00
|
|
|
Read an **analog** signal (`0` through `1023`) from the
|
|
|
|
[pin](/device/pins) you say.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```sig
|
|
|
|
pins.analogReadPin(AnalogPin.P0)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
2016-06-29 21:41:35 +02:00
|
|
|
* a [string](/reference/types/string) with the name of the pin
|
2016-06-23 23:29:32 +02:00
|
|
|
you say (`P0` through `P4`, or `P10`)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
### Returns
|
|
|
|
|
2016-06-23 23:29:32 +02:00
|
|
|
* a [number](/reference/types/number) from `0` through `1023`
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-06-23 23:29:32 +02:00
|
|
|
This program reads pin `P1` and shows the number
|
|
|
|
on the LED screen.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
|
|
|
let value = pins.analogReadPin(AnalogPin.P1)
|
2016-06-23 23:29:32 +02:00
|
|
|
basic.showNumber(value)
|
2016-03-26 00:47:20 +01:00
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2016-06-29 21:41:35 +02:00
|
|
|
#### ~hint
|
|
|
|
|
|
|
|
If you are using **analog read pin** with another micro:bit
|
|
|
|
running **analog write pin**, it is a good idea to check
|
|
|
|
**analog read pin** many times and then take an average.
|
|
|
|
|
|
|
|
#### ~
|
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
### See also
|
|
|
|
|
2016-06-23 01:24:14 +02:00
|
|
|
[micro:bit pins](/device/pins),
|
|
|
|
[on pin pressed](/reference/input/on-pin-pressed),
|
|
|
|
[analog write pin](/reference/pins/analog-write-pin),
|
|
|
|
[digital read pin](/reference/pins/digital-read-pin),
|
|
|
|
[digital write pin](/reference/pins/digital-write-pin)
|