Using the Pins
Each pin on the BBC micro:bit is represented by an object called pinN where N is the pin number. So, for example, to do things with the pin labelled with a 0 (zero), use the object called pin0.
Pins 0 1 and 2 are touch inputs and have a 10M ohm Pullup
Input
pin0.is_touched(): Return True if the pin is being touched with a finger, otherwise return False
pin0.read_digital() Return 1 if the pin is high, and 0 if it’s low.
pin0.read_analog() Read the voltage applied to the pin, and return it as an integer between 0 (meaning 0V) and 1023 (meaning 3.3V).
Output
pin0.write_digital(1) Sets pin 0 to High
pin0.write_digital(0) Sets pin 0 to Low
write_analog(value) NOTE it is PCM output not true Analog Output a PWM signal on the pin, with the duty cycle proportional to the provided value. The value may be either an integer or a floating point number between 0 (0% duty cycle) and 1023 (100% duty).
set_analog_period(period)
Set the period of the PWM signal being output to period in milliseconds. The minimum valid value is 1ms.
set_analog_period_microseconds(period)
Set the period of the PWM signal being output to period in microseconds. The minimum valid value is 35µs.