Main Content

write

Write data to shift register

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

Description

write(register,value) writes data to the data pin of a serial-in/parallel-out (SIPO) shift register.

example

write(register,value,precision) also specifies the data precision.

example

Examples

collapse all

Create an Arduino® object with the 'ShiftRegister' library.

a = arduino('COM4','Uno','Libraries','ShiftRegister');

Connect to the SIPO shift register on your Arduino board.

register = shiftRegister(a,'74HC595','D3','D6','D7');

Write data to the data pin of the register.

write(register,23);

Create an Arduino® object with the 'ShiftRegister' library.

a = arduino('COM4','Uno','Libraries','ShiftRegister');

Connect to the SIPO shift register on your Arduino board.

register = shiftRegister(a,'74HC595','D3','D6','D7');

Write data to the data pin of the register with a specified precision.

write(register,300,'uint16');

Input Arguments

collapse all

Shift register connection, specified as a shiftRegister object.

Data to write to the data pin of a SIPO shift register. Specify the data either as a number or as a character vector of '1' or '0' or as a vector of 1 or 0, or as a hexadecimal or binary.

Note

  • If you specify the data as a number, the value must be within the range of precision.

  • If you specify the data as a character vector of '1' or '0', the length of the vector must match with precision and the vector must start with the most significant bit or the highest bit for the shift register. For example, if you write a character vector of '00001010' with length 8, specify the precision as 'uint8'.

  • If you specify the data as a vector of 1 or 0, the vector must start with the least significant bit or the lowest bit for the shift register and the length of the vector must match with precision. For example, if you write a vector of [0 0 0 0 1 0 1 0] of length 8, specify precision as 'uint8'.

Data precision, specified as one of the following character vectors:

  • 'uint8'

  • 'uint16'

  • 'uint32'

  • 'uint64'

Data can be also be specified in the following formats:

  • hexadecimal

  • binary

  • char

  • string

Version History

Introduced in R2016b