Main Content

configurePin

Configure and display pin modes on BBC micro:bit board

Description

pinMode = configurePin(microbitObj,pin) displays the mode of the pin on the BBC micro:bit board, specified as a microbit object .

example

configurePin(microbitObj,pin,mode) sets the mode on the specified pin on the BBC micro:bit board, specified as a microbit object.

example

Examples

collapse all

microbitObj = microbit('COM3');
configurePin(microbitObj,'P0')
ans =

Unset
microbitObj = microbit('COM3');
configurePin(microbitObj,'P0','PWM');

Display current pin mode.

pinMode = configurePin(microbitObj,'P0')
pinMode =

PWM

Display current pin mode.

microbitObj = microbit('COM3');
pinModeP0 = configurePin(microbitObj,'P0')
pinModeP0 =

AnalogInput

Change the pin mode to 'Unset' and display the current mode.

configurePin(microbitObj,'P0','Unset');
pinModeP0 = configurePin(microbitObj,'P0')
pinModeP0 =

Unset

Input Arguments

collapse all

BBC micro:bit hardware connection, specified as a microbit object created with the microbit function.

Pin number on the BBC micro:bit board, specified as a character vector.

Example: 'P0'

Pin mode specified as a character vector. Valid pin modes are:

  • 'AnalogInput' — Acquire analog signals from the pin. The pins that support analog input signals are P0, P1, P2, P3, P4 and P10.

  • 'DigitalInput' — Acquire digital signals from the pin.

  • 'DigitalOutput' — Generate digital signals from the pin.

  • 'I2C' — Specify that the pin be used as an I2C (Inter-Integrated Circuit) interface. The pins that support I2C are P19 and P20.

  • 'PWM' — Specify that the pin uses PWM (Pulse Width Modulation).

  • 'SPI' — Specify that the pin be used as an SPI (Serial Peripheral Interface). The pins that support SPI are P13, P14, and P15.

  • 'Unset' — Clear the mode of the pin. The pin is no longer reserved and can be automatically set at the next operation.

Output Arguments

collapse all

Current mode of the pin on BBC micro:bit board, returned as a character vector.

Version History

Introduced in R2017b