Skip to content

Digital inputs

Digital input

Getting an input by reading the value of a digital pin. All pins can be referred to as P0..P20.

The digital input returns either 0 or 1. This can be interpreted as False = 0, True = 1

In blocks

digital readpinP0

In python

from microbit import *

while True:
    if pin0.read_digital():
        display.show(Image.HAPPY)
    else:
        display.show(Image.SAD)

Also see: