Main Content

shiftRegister

Connection to shift register on Arduino hardware

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

Description

A shiftRegister object represents a connection to a shift register on Arduino® hardware. The 74HC165, 74HC595, and 74HC164 type shift registers are supported. Attach a shift register to the appropriate pins on the Arduino hardware. Create a shiftRegister object using the shiftRegister function. You can read from and write to the shift register in MATLAB® using the object functions. Manipulate peripheral devices attached to the shift register, such as LEDs.

Note

MATLAB Support Package for Arduino Hardware does not support read function for 74HC595 shift register.

Creation

Description

register = shiftRegister(a,'74hc165',dataPin,clockPin,loadPin,clockEnablePin) creates a connection to the 74hc165 shift register connected to your Arduino board using the Arduino object a, dataPin to input or output data, clockPin to signal read or write, loadPin to load parallel input data, and clockEnablePin to enable or disable clock.

example

register = shiftRegister(a,'74hc595',dataPin,clockPin,latchPin) creates a connection to the 74hc595 shift register using the latchPin to latch input data.

example

register = shiftRegister(a,'74hc595',dataPin,clockPin,latchPin,resetPin) enables reset of the outputs of 74hc595 shift register.

example

register = shiftRegister(a,'74hc164',dataPin,clockPin) creates a connection to the 74hc164 shift register.

example

register = shiftRegister(a,'74hc164',dataPin,clockPin,resetPin) enables reset of the outputs of 74hc164 shift register.

example

Input Arguments

expand all

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

Example: register = shiftRegister(a,'74HC165','D3','D6','D7','D10') creates a connection to the 74HC165 shift register on the specified arduino object a.

Shift register serial pin to input or output data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D3'. It is usually connected to the DS or SER pin on the shift register.

Example: register = shiftRegister(a,'74HC165','D3','D6','D7','D10') creates a connection to a 74HC165 shift register whose serial pin is connected to digital pin 3 on the Arduino hardware.

Data Types: char

Shift register clock pin to signal read or write, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D6'. It is usually connected to the SHCP or SRCLK pin on the shift register.

Example: register = shiftRegister(a,'74HC165','D3','D6','D7','D10') creates a connection to a 74HC165 shift register whose clock pin is connected to digital pin 6 on the Arduino hardware.

Data Types: char

Shift register latch pin to latch input data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D7'. It is usually connected to the STCP or RCLK pin on the shift register.

Example: register = shiftRegister(a,'74HC595','D3','D6','D7') creates a connection to a 74HC595 shift register whose latch pin is connected to digital pin 7 on the Arduino hardware.

Data Types: char

Shift register parallel load pin to load parallel input data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D7'. It is usually connected to the PL pin on the shift register.

Example: register = shiftRegister(a,'74HC165','D3','D6','D7','D10') creates a connection to a 74HC165 shift register whose load pin is connected to digital pin 7 on the Arduino hardware.

Data Types: char

Shift register clock enable pin to enable or disable clock, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D10'. It is usually connected to the CE pin on the shift register.

Example: register = shiftRegister(a,'74HC165','D3','D6','D7','D10') creates a connection to a 74HC165 shift register whose clock enable pin is connected to digital pin 10 on the Arduino hardware.

Data Types: char

Shift register reset pin to reset output, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D10'. It is usually connected to the CLR pin on the shift register.

Example: register = shiftRegister(a,'74HC595','D3','D6','D7','D10') creates a connection to a 74HC595 shift register whose reset pin is connected to digital pin 10 on the Arduino hardware.

Data Types: char

Properties

expand all

This property is read-only.

Shift register model number, specified as a character vector. Supported shift registers are 74HC165, 74HC595, and 74HC164.

Example:

>> register.Model

ans =

    '74HC164'

Data Types: char

This property is read-only.

Shift register serial pin to input or output data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D3'. It is usually connected to the DS or SER pin on the shift register.

Example:

>> register.DataPin

ans =

    'D3'

Data Types: char

This property is read-only.

Shift register clock pin to signal read or write, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D6'. It is usually connected to the SHCP or SRCLK pin on the shift register.

Example:

>> register.ClockPin

ans =

    'D6'

Data Types: char

This property is read-only.

Shift register latch pin to latch input data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D7'. It is usually connected to the STCP or RCLK pin on the shift register. It is only for the 74HC595 shift register.

Example:

>> register.LatchPin

ans =

    'D7'

Data Types: char

This property is read-only.

Shift register parallel load pin to load parallel input data, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D7'. It is usually connected to the PL pin on the shift register. It is only for the 74HC165 shift register.

Example:

>> register.LoadPin

ans =

    'D7'

Data Types: char

This property is read-only.

Shift register clock enable pin to enable or disable clock, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D10'. It is usually connected to the CE pin on the shift register. It is only for the 74HC165 shift register.

Example:

>> register.ClockEnablePin

ans =

    'D10'

Data Types: char

This property is read-only.

Shift register reset pin to reset output, specified as a character vector of the form 'Dx' where x is the Arduino pin number. For example, 'D10'. It is usually connected to the CLR pin on the shift register. It is only for the 74HC164 shift register.

Example:

>> register.ResetPin

ans =

    'D10'

Data Types: char

Object Functions

Use these object functions to read from and write to your shift register.

readRead data from shift register
writeWrite data to shift register
resetClear all outputs of shift register

Examples

collapse all

Connect to a 74HC165 shift register using your Arduino® board.

Create an Arduino object with the 'ShiftRegister' library.

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

Connect to the shift register connected to your Arduino board.

register = shiftRegister(a,'74HC165','D3','D6','D7','D10')
register = 
  shiftRegister with properties:

           Model: '74HC165'      
         DataPin: 'D3'           
        ClockPin: 'D6'           
         LoadPin: 'D7'           
  ClockEnablePin: 'D10'          

Connect to a 74HC595 shift register using your Arduino board.

Connect to the shift register connected to your Arduino board.

a = arduino('COM4','Uno','Libraries','ShiftRegister');
register = shiftRegister(a,'74HC595','D3','D6','D7')
register = 
  shiftRegister with properties:

           Model: '74HC595'      
         DataPin: 'D3'           
        ClockPin: 'D6'           
        LatchPin: 'D7'           
        ResetPin: Not specified

Connect to a 74HC595 shift register, and specify the resetPin to reset the outputs.

Connect to the shift register on your Arduino board.

a = arduino('COM4','Uno','Libraries','ShiftRegister');
register = shiftRegister(a,'74HC595','D3','D6','D7','D8')
register = 
  shiftRegister with properties:

           Model: '74HC595'      
         DataPin: 'D3'           
        ClockPin: 'D6'           
        LatchPin: 'D7'           
        ResetPin: 'D8'           

Connect to a 74HC164 shift register using your Arduino board.

Connect to the shift register connected to your Arduino board.

a = arduino('COM4','Uno','Libraries','ShiftRegister');
register = shiftRegister(a,'74HC164','D3','D6')
register = 
  shiftRegister with properties:

           Model: '74HC164'      
         DataPin: 'D3'           
        ClockPin: 'D6'           
        ResetPin: Not specified

Connect to a 74HC164 shift register, and specify the resetPin to reset the outputs.

Connect to the shift register on your Arduino board.

a = arduino('COM4','Uno','Libraries','ShiftRegister');
register = shiftRegister(a,'74HC164','D3','D6','D7')
register = 
  shiftRegister with properties:

           Model: '74HC164'      
         DataPin: 'D3'           
        ClockPin: 'D6'           
        ResetPin: 'D7'           

Version History

Introduced in R2016b

See Also

| | |