This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

configurePin

Set Arduino pin mode

Syntax

pinMode = configurePin(a,pin)
configurePin(a,pin,mode)

Description

example

pinMode = configurePin(a,pin) displays the mode the specified pin on the Arduino® hardware in connection a .

example

configurePin(a,pin,mode) sets the specified pin on the Arduino hardware in connection a to the specified mode.

Examples

collapse all

a = arduino('COM4','Uno');
configurePin(a,'A2')
ans = 
'Unset'
a = arduino('COM4','Uno');
configurePin(a,'A4','I2C');

Display current pin mode.

pinMode = configurePin(a,'A4')
pinMode = 
'I2C'
a = arduino('COM4','Uno');
configurePin(a,'D3','pullup');

Display current pin mode.

pinmode = configurePin(a,'D3')
pinmode = 
'Pullup'

Display current pin mode and reset it to 'Unset'.

a = arduino('COM4','Uno');
configurePin(a,'D3','pullup');
pinMode = configurePin(a,'D3')
pinMode = 
'Pullup'

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

configurePin(a,'D3','Unset');
pinMode = configurePin(a,'D3')
pinMode = 
'Unset'

Input Arguments

collapse all

Arduino hardware connection created using arduino, specified as an object.

Example: a = arduino;

Pin number on the physical hardware, specified as a character vector.

Example: D3 or A1.

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

  • AnalogInput: acquire analog signals from pin

  • DigitalInput: acquire digital signals from pin

  • DigitalOutput: generate digital signals from pin

  • I2C: specify a pin to use with I2C protocol

  • Interrupt: specify pin in interrupt mode to be used in rotaryEncoder

  • Pullup: specify pin to use a pullup switch

  • PWM: specify pin to use a pulse width modulator

  • Servo: specify pin to use a servo

  • SPI: specify a pin to use with SPI protocol

  • Tone: specify pin to use for playTone

  • Ultrasonic: specify pin to used with ultrasonic sensor

  • Unset: clears pin designation. The pin is no longer reserved and can be automatically set at the next operation.

Pins are configured on first usage. You can reset the pin mode to change the mode. If you want to use a pullup, you must set the mode to 'pullup'.

Output Arguments

collapse all

Current mode of pin, returned as a character vector.

Introduced in R2015b