Main Content

readDigitalPin

Read data from a specified pin on Arduino hardware

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

value = readDigitalPin(a,pin) reads data from the specified pin on the Arduino® hardware in connection a.

example

Examples

collapse all

Create a connection to Arduino hardware and read digital pin 13.

a = arduino;
readDigitalPin(a,'D13')
ans = 1

Input Arguments

collapse all

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

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

Note

If you are using an analog pin to read a digital value, the pin will be configured in DigitalInput mode.

Output Arguments

collapse all

Value acquired from the pin, returned as a numeric double.

More About

collapse all

Code Generation Using MATLAB Function Block

  • Use readDigitalPin 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 to the appropriate mode using configurePin before using readDigitalPin in the MATLAB Function block.

Version History

Introduced in R2014b