Digital Read Pin

Read a digital (0 or 1) signal from a pin on the micro:bit board.

digital readpinP0
function digitalReadPin(name: DigitalPin): int32;

Some pins are also used by the LED screen. Please read the page about pins carefully.

Parameters

  • name is a string that stores the name of the pin (P0, P1, or P2, up through P20)

Returns

Example: football score keeper

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.

ifthendigital readpinP01=11score10000digital writepinP2topause (ms)shownumberdigital writepinP2tochangescorebyforeverscoreshownumberon start

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.

input.onButtonPressed(Button.B, () => {
    pins.digitalWritePin(DigitalPin.P1, 1);
    basic.pause(500);
    pins.digitalWritePin(DigitalPin.P1, 0);
});

Remember to connect GND on both micro:bits together!

See also

micro:bit pins, digital write pin, analog read pin, analog write pin, on pin pressed, pin is pressed

ifthendigital readpinP01=11score10000digital writepinP2topause (ms)shownumberdigital writepinP2tochangescorebyforeverscoreshownumberon start