Rewrote in simpler language. Added another example.
This commit is contained in:
parent
e65a521bd4
commit
c0a75d1845
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user