Contenu principal

readDigitalPin

R2026b

Read data from a specified pin on Arduino hardware

Description

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

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

Alternative Functionality

App

Use the Pin Explorer pane and Pin Configuration panel in the Arduino Explorer to read data from a specified pin on Arduino or any other supported hardware in MATLAB and MATLAB Online™. The Pin Configuration panel displays the options you can use to configure the selected pin. In the Pin Configuration panel, set the Mode as Digital Input (Read) and if required specify a Label to uniquely identify the pin. You can also use the plot panel of the app to interactively view data read from the board.

Version History

Introduced in R2014b