From e65a521bd42d1e50084ee6e5a0fed5d3ef302441 Mon Sep 17 00:00:00 2001 From: Ron Hale-Evans Date: Wed, 22 Jun 2016 15:19:10 -0700 Subject: [PATCH 1/3] Rewrote in simple language. Added second example. --- docs/reference/pins/digital-read-pin.md | 46 ++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/docs/reference/pins/digital-read-pin.md b/docs/reference/pins/digital-read-pin.md index 22ff2443..baa98dbe 100644 --- a/docs/reference/pins/digital-read-pin.md +++ b/docs/reference/pins/digital-read-pin.md @@ -1,24 +1,32 @@ # Digital Read Pin -The digital read pin function. - -Digitally read the specified [pin](/device/pins) (``P0``, ``P1``, ``P2``, ...) as digital. **Some pins are also used by the display, read the [pin documentation ](/device/pins) carefully.** +Read a **digital** (`0` or `1`) signal from a [pin](/device/pins) on +the micro:bit board. ```sig pins.digitalReadPin(DigitalPin.P3) ``` +### ~avatar + +Some pins are also used by the [LED screen](/device/screen). +Please read the [page about pins](/device/pins) carefully. + +### ~ + ### Parameters -* name - the pin name ``P0``, ``P1``, ``P2``, ... +* a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``) ### Returns -* [Number](/reference/types/number) - 0 or 1 +* a [number](/reference/types/number) that can be `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: +This program reads pin `P0` to find when a goal is scored. When `P0` +is `1`, the program makes the score bigger and plays a buzzer sound +through `P2` with ``digital write pin``. ```blocks let score = 0 @@ -34,7 +42,29 @@ basic.forever(() => { }) ``` +This program is a remote control for the score keeper program. If you +connect `P1` on the remote control micro:bit to `P0` on the score +keeper micro:bit, you can press button `B` on the remote to buzz and +make the score bigger on the other micro:bit. + +```blocks +input.onButtonPressed(Button.B, () => { + pins.digitalWritePin(DigitalPin.P1, 1); + basic.pause(500); + pins.digitalWritePin(DigitalPin.P1, 0); +}); +``` +#### ~hint + +Remember to connect `GND` on both micro:bits together! + +#### ~ + ### See also -[micro:bit pins](/device/pins), [digital write pin](/reference/pins/digital-write-pin), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [on pin pressed](/reference/input/on-pin-pressed), [pin is pressed](/reference/input/pin-is-pressed) - +[micro:bit pins](/device/pins), +[digital write pin](/reference/pins/digital-write-pin), +[analog read pin](/reference/pins/analog-read-pin), +[analog write pin](/reference/pins/analog-write-pin), +[on pin pressed](/reference/input/on-pin-pressed), +[pin is pressed](/reference/input/pin-is-pressed) From c0a75d1845632f178c6cc3fd44e28f2f6af9ecb8 Mon Sep 17 00:00:00 2001 From: Ron Hale-Evans Date: Wed, 22 Jun 2016 15:35:20 -0700 Subject: [PATCH 2/3] Rewrote in simpler language. Added another example. --- docs/reference/pins/digital-write-pin.md | 38 ++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/docs/reference/pins/digital-write-pin.md b/docs/reference/pins/digital-write-pin.md index 90d862de..72771996 100644 --- a/docs/reference/pins/digital-write-pin.md +++ b/docs/reference/pins/digital-write-pin.md @@ -1,19 +1,29 @@ # Digital Write Pin -Write the value ``0`` or ``1`` to the specified (digital) [pin](/device/pins). **Some pins are also used by the display, read the [pin documentation ](/device/pins) carefully.** +Write a **digital** (`0` or `1`) signal to a [pin](/device/pins) on +the micro:bit board. ```sig pins.digitalWritePin(DigitalPin.P1, 1) ``` +### ~avatar + +Some pins are also used by the [LED screen](/device/screen). +Please read the [page about pins](/device/pins) carefully. + +### ~ + ### Parameters -* name - the pin name (``P0``, ``P1``, ``P2``, ...) -* value - [Number](/reference/types/number); 0 or 1 +* a [string](/reference/types/string) that stores the name of the pin (``P0``, ``P1``, or ``P2``, up through ``P20``) +* a [number](/reference/types/number) that can be either `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: +This program reads pin `P0` to find when a goal is scored. When `P0` +is `1`, the program makes the score bigger and plays a buzzer sound +through `P2` with ``digital write pin``. ```blocks let score = 0 @@ -29,7 +39,25 @@ basic.forever(() => { }) ``` +This program is a remote control for the score keeper program. If you +connect `P1` on the remote control micro:bit to `P0` on the score +keeper micro:bit, you can press button `B` on the remote. This program +will use ``digital write pin`` to make the other micro:bit buzz and +make the score bigger. + +```blocks +input.onButtonPressed(Button.B, () => { + pins.digitalWritePin(DigitalPin.P1, 1); + basic.pause(500); + pins.digitalWritePin(DigitalPin.P1, 0); +}); +``` + ### See also -[micro:bit pins](/device/pins), [digital read pin](/reference/pins/digital-read-pin), [analog read pin](/reference/pins/analog-read-pin), [analog write pin](/reference/pins/analog-write-pin), [on pin pressed](/reference/input/on-pin-pressed) +[micro:bit pins](/device/pins), +[digital read pin](/reference/pins/digital-read-pin), +[analog read pin](/reference/pins/analog-read-pin), +[analog write pin](/reference/pins/analog-write-pin), +[on pin pressed](/reference/input/on-pin-pressed) From ccf405e64cf3b9d06e78be2c28d46b4d83f33847 Mon Sep 17 00:00:00 2001 From: Ron Hale-Evans Date: Wed, 22 Jun 2016 16:24:14 -0700 Subject: [PATCH 3/3] Rewrote in simple language --- docs/reference/pins/analog-read-pin.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/reference/pins/analog-read-pin.md b/docs/reference/pins/analog-read-pin.md index d1ee83bd..12768b3f 100644 --- a/docs/reference/pins/analog-read-pin.md +++ b/docs/reference/pins/analog-read-pin.md @@ -1,6 +1,7 @@ # Analog Read Pin -Read the specified [pin](/device/pins) (P0, P1, P2) as analog. +Read an **analog** signal (`0` through `1023`) from the +[pin](/device/pins) you say. ```sig pins.analogReadPin(AnalogPin.P0) @@ -8,13 +9,14 @@ pins.analogReadPin(AnalogPin.P0) ### Parameters -* name - the pin name (`P0`, `P1`, or `P2`) +* a [string](/reference/types/string) that stores the pin you say (`P0` through `P4`, or `P10`) ### Returns -* [Number](/reference/types/number) - a number between 0 and 1023 (included) +* a [number](/reference/types/number) from `0` through `1024` -The following code reads `P1` and charts it on the screen: +This program reads pin `P1` and shows the number as a +[bar graph](/reference/led/plot-bar-graph). ```blocks basic.forever(() => { @@ -25,5 +27,9 @@ basic.forever(() => { ### See also -[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) +[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)