Main Content

readCount

Read current count value from encoder connected to MKR Motor Carrier or Nano Motor Carrier

Since R2020a

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

Description

[count] = readCount(encoder) returns the current count value from the encoder.

[count,timestamp] = readCount(encoder) returns the current count value from the encoder along with the timestamp in datetime format.

[count] = readCount(encoder,'Reset',reset) resets the count value from the encoder to zero when 'Reset' is set to 'true'.

[count,timestamp] = readCount(encoder,'Reset',reset) resets the count value from the encoder to zero when 'Reset' is set to 'true' and the timestamp in datetime format.

Examples

collapse all

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current absolute count value of encoder register of Nano Motor Carrier.

count = readCount(encoder);

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current absolute count value of encoder register of Nano Motor Carrier.

[count,timestamp] = readCount(encoder);

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current absolute count value of encoder register of Nano Motor Carrier.

count = readCount(encoder,'Reset',true);

Create a connection to the Nano Motor Carrier.

arduinoObj = arduino('/dev/ttyACM0','Nano33IoT','Libraries','MotorCarrier');
mcObj = motorCarrier(arduinoObj);

Create a connection to the rotary encoder.

encoder = rotaryEncoder(mcObj,1);

Read the current absolute count value of encoder register of Nano Motor Carrier.

[count,timestamp] = readCount(encoder,'Reset',true);

Input Arguments

collapse all

Connection to the rotary encoder on MKR Motor Carrier or Nano Motor Carrier, specified as an object.

Flag to reset count value to 0 after each read operation, specified as the comma-separated pair consisting of 'Reset' and either false or true. This is an optional argument.

Data Types: logical

Output Arguments

collapse all

Current count value of the encoder, returned as a number.

Data Types: int32

Time at which MATLAB® reads the count, specified as datetime.

Data Types: datetime

Version History

Introduced in R2020a