on Pulsed

Set a pin to use as a digital input and then run some code when the pin pulses either high or low.

pins.onPulsed(DigitalPin.P0, PulseValue.High, () => { });

Simulator: This function needs real hardware to work with. It’s not supported in the simulator.

Parameters

  • name: the micro:bit hardware pin to set for digital input (P0 through P20).
  • pulse: the state that will cause the code inside the block to run, either high or low.
  • body: the code to run when the pin in name is pulsed to the state set in pulse.

Example

Configure pin P2 for digital input. Display the string "LOW" whenever P2 pulses low.

pins.onPulsed(DigitalPin.P2, PulseValue.Low, () => {
    basic.showString("LOW");
});

See also

servo set pulse, pulse duration, digital read pin