configurePin

Set Arduino 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.

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use configurePin in a MATLAB® Function block with the Simulink® Support Package for Arduino Hardware to generate code that can be deployed on Arduino Hardware.

  • Configure the Arduino peripherals using configurePin before using it in the MATLAB Function block.

  • The function does not return any output during code generation.

  • The following modes are currently supported for code generation : AnalogInput, DigitalInput, DigitalOutput, Pullup, PWM, and Unset.

Introduced in R2015b