MATLAB Examples

digitalRead

Reads the value from the specified digital pin. Returns digital pins state as a n x 2 array, representing KEY-VALUE pairs of digital pins.

Contents

Syntax

readings = e.digitalRead(pins);

Description

e.digitalRead(pin); Reads the value from the specified digital pin.
e.digitalRead(pin1;pin2l..pinN); Reads the value from multiple digital pin.

Examples

  • Read value from digital pin 3
  • Connect to Engduino and start reading digital value from pin 3

    % Check if the Engduino object already exists. Otherwise initialize it.
    if (~exist('e', 'var'))
            e = engduino();
    end
    while (true)
        % Get reading from analog pin 3
        pin3 = e.digitalRead(3);
    end
    

  • Read value from digital pin 1,2,3
  • Connect to Engduino and start reading multiple digital pin values

    % Check if the Engduino object already exists. Otherwise initialize it.
    if (~exist('e', 'var'))
            e = engduino();
    end
    
    while (true)
        % Get reading from digital pin 1,2,3
        readings = e.digitalRead([1;2;3;]);
        pin1_val = readings(1,2)
        pin2_val = readings(2,2)
        pin3_val = readings(3,2)
    end
    

    Input Arguments

    pins Input parameter can be scalars or vectors enabling setting multiple pins at once.

    Output Arguments

    readings A n x 2 array of requested pins state. eg. [pin_no,pin_value]