This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
SPIShiftRegisterOut< N > Class Template Referenceabstract

A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bus. More...

#include <SPIShiftRegisterOut.hpp>

Inheritance diagram for SPIShiftRegisterOut< N >:
Collaboration diagram for SPIShiftRegisterOut< N >:

Public Member Functions

 SPIShiftRegisterOut (pin_t latchPin=SS, uint8_t bitOrder=MSBFIRST)
 Create a new SPIShiftRegisterOut object with a given bit order, and a given number of outputs. More...
 
void begin () override
 Initialize the shift register. More...
 
void update () override
 Write the state buffer to the physical outputs. More...
 
void pinMode (UNUSED_PARAM pin_t pin, UNUSED_PARAM uint8_t mode) override __attribute__((deprecated))
 The pinMode function is not implemented because the mode is OUTPUT by definition. More...
 
virtual void pinMode (pin_t pin, uint8_t mode)=0
 Set the mode of a given pin. More...
 
void digitalWrite (pin_t pin, uint8_t val) override
 Set the state of a given output pin. More...
 
int digitalRead (pin_t pin) override
 Get the current state of a given output pin. More...
 
analog_t analogRead (pin_t pin) override __attribute__((deprecated))
 The analogRead function is deprecated because a shift is always digital. More...
 
void analogWrite (pin_t pin, analog_t val) override __attribute__((deprecated))
 The analogWrite function is not deprecated because a shift is always digital. More...
 
pin_t red (pin_t id)
 Get the red output pin of the given LED. More...
 
Array< pin_t, N/3 > redPins ()
 Get an array containing all pins with red LEDs. More...
 
pin_t green (pin_t id)
 Get the green output pin of the given LED. More...
 
Array< pin_t, N/3 > greenPins ()
 Get an array containing all pins with green LEDs. More...
 
pin_t blue (pin_t id)
 Get the blue output pin of the given LED. More...
 
Array< pin_t, N/3 > bluePins ()
 Get an array containing all pins with blue LEDs. More...
 
Array< pin_t, N > pins () const
 Get an array containing all pins of the element. More...
 
pin_t pin (pin_t pin) const
 Get the extended IO pin number of a given physical pin of this extended IO element. More...
 
pin_t operator[] (pin_t pin) const
 Get the extended IO pin number of a given physical pin of this extended IO element. More...
 
pin_t getLength () const
 Get the number of pins this IO element has. More...
 
pin_t getEnd () const
 Get the largest global extended IO pin number that belongs to this extended IO element. More...
 
pin_t getStart () const
 Get the smallest global extended IO pin number that belongs to this extended IO element. More...
 

Static Public Member Functions

static constexpr uint16_t length ()
 
static void beginAll ()
 Initialize all extended IO elements. More...
 
static DoublyLinkedList< ExtendedIOElement > & getAll ()
 Get the list of all Extended IO elements. More...
 

Protected Attributes

const pin_t latchPin
 
const uint8_t bitOrder
 
BitArray< N > buffer
 
bool dirty = true
 
ExtendedIOElementnext
 
ExtendedIOElementprevious
 

Private Attributes

const pin_t start
 
const pin_t end
 

Static Private Attributes

static pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
 
static DoublyLinkedList< ExtendedIOElementelements
 

Detailed Description

template<uint8_t N>
class SPIShiftRegisterOut< N >

A class for serial-in/parallel-out shift registers, like the 74HC595 that are connected to the SPI bus.

Template Parameters
NThe number of bits in total. Usually, shift registers (e.g. the 74HC595) have eight bits per chip, so length = 8 * k where k is the number of cascaded chips.
Examples
1.SPI-Blink.ino, 2.First-Input.ino, 2.Note-Range-LEDs.ino, 2.RGB-LED-Chaser.ino, 3.NoteLEDBar.ino, and Toggle-LEDs.ino.

Definition at line 23 of file SPIShiftRegisterOut.hpp.

Constructor & Destructor Documentation

◆ SPIShiftRegisterOut()

template<uint8_t N>
SPIShiftRegisterOut< N >::SPIShiftRegisterOut ( pin_t  latchPin = SS,
uint8_t  bitOrder = MSBFIRST 
)

Create a new SPIShiftRegisterOut object with a given bit order, and a given number of outputs.

Multiple shift registers can be cascaded by connecting the serial output of the first one to the input of the second one:

SCK >───────────┬──────────────────────┬───────── ⋯
┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓
┃ SH_CP ┃ ┃ SH_CP ┃
MOSI >───┨ DS Q7S ┠──────┨ DS Q7S ┠─ ⋯
┃ ST_CP ┃ ┃ ST_CP ┃
┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛
CS >───────────┴──────────────────────┴───────── ⋯
Parameters
latchPinThe digital output pin connected to the latch pin (ST_CP or RCLK) of the shift register.
bitOrderEither MSBFIRST (most significant bit first) or LSBFIRST (least significant bit first).

Definition at line 10 of file SPIShiftRegisterOut.ipp.

Member Function Documentation

◆ begin()

template<uint8_t N>
void SPIShiftRegisterOut< N >::begin ( )
overridevirtual

Initialize the shift register.


Setup the SPI interface, set the CS pin to output mode, and set all shift register outputs to LOW.

Implements ExtendedIOElement.

Definition at line 14 of file SPIShiftRegisterOut.ipp.

◆ update()

template<uint8_t N>
void SPIShiftRegisterOut< N >::update ( )
overridevirtual

Write the state buffer to the physical outputs.

Implements ExtendedIOElement.

Definition at line 21 of file SPIShiftRegisterOut.ipp.

◆ pinMode() [1/2]

template<uint8_t N>
void ShiftRegisterOutBase< N >::pinMode ( UNUSED_PARAM pin_t  pin,
UNUSED_PARAM uint8_t  mode 
)
inlineoverrideinherited

The pinMode function is not implemented because the mode is OUTPUT by definition.

Definition at line 42 of file ShiftRegisterOutBase.hpp.

◆ pinMode() [2/2]

virtual void ExtendedIOElement::pinMode ( pin_t  pin,
uint8_t  mode 
)
pure virtualinherited

Set the mode of a given pin.

Note
This function might not be implemented by all subclasses.
Some extended IO types, such as shift registers, can only be used as outputs.
On others, it might be implemented, but it could impact all pins of the IO element. For example, enabling the internal pull-up resistor on an analog multiplexer affects all pins of the mux.
Parameters
pinThe (zero-based) pin of this IO element.
modeThe mode to set the pin to (e.g. INPUT, OUTPUT or INPUT_PULLUP).

◆ digitalWrite()

template<uint8_t N>
void ShiftRegisterOutBase< N >::digitalWrite ( pin_t  pin,
uint8_t  val 
)
overridevirtualinherited

Set the state of a given output pin.

Parameters
pinThe shift register pin to set.
valThe value to set the pin to. (Either HIGH (1) or LOW (0))

Implements ExtendedIOElement.

Definition at line 12 of file ShiftRegisterOutBase.ipp.

◆ digitalRead()

template<uint8_t N>
int ShiftRegisterOutBase< N >::digitalRead ( pin_t  pin)
overridevirtualinherited

Get the current state of a given output pin.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1The state of the pin is HIGH.

Implements ExtendedIOElement.

Definition at line 19 of file ShiftRegisterOutBase.ipp.

◆ analogRead()

template<uint8_t N>
analog_t ShiftRegisterOutBase< N >::analogRead ( pin_t  pin)
inlineoverridevirtualinherited

The analogRead function is deprecated because a shift is always digital.

Parameters
pinThe shift register pin to read from.
Return values
0The state of the pin is LOW.
1023The state of the pin is HIGH.

Implements ExtendedIOElement.

Definition at line 78 of file ShiftRegisterOutBase.hpp.

◆ analogWrite()

template<uint8_t N>
void ShiftRegisterOutBase< N >::analogWrite ( pin_t  pin,
analog_t  val 
)
inlineoverridevirtualinherited

The analogWrite function is not deprecated because a shift is always digital.

Parameters
pinThe shift register pin to set.
valThe value to set the pin to. A value greater or equal to 0x80 will set the pin to a HIGH state, a value less than 0x80 will set the pin to a LOW state.

Implements ExtendedIOElement.

Definition at line 92 of file ShiftRegisterOutBase.hpp.

◆ red()

template<uint8_t N>
pin_t ShiftRegisterOutBase< N >::red ( pin_t  id)
inherited

Get the red output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 35 of file ShiftRegisterOutBase.ipp.

◆ redPins()

template<uint8_t N>
Array< pin_t, N/3 > ShiftRegisterOutBase< N >::redPins ( )
inherited

Get an array containing all pins with red LEDs.

Definition at line 40 of file ShiftRegisterOutBase.ipp.

◆ green()

template<uint8_t N>
pin_t ShiftRegisterOutBase< N >::green ( pin_t  id)
inherited

Get the green output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 24 of file ShiftRegisterOutBase.ipp.

◆ greenPins()

template<uint8_t N>
Array< pin_t, N/3 > ShiftRegisterOutBase< N >::greenPins ( )
inherited

Get an array containing all pins with green LEDs.

Definition at line 29 of file ShiftRegisterOutBase.ipp.

◆ blue()

template<uint8_t N>
pin_t ShiftRegisterOutBase< N >::blue ( pin_t  id)
inherited

Get the blue output pin of the given LED.

Parameters
idThe zero-based LED number.

Definition at line 46 of file ShiftRegisterOutBase.ipp.

◆ bluePins()

template<uint8_t N>
Array< pin_t, N/3 > ShiftRegisterOutBase< N >::bluePins ( )
inherited

Get an array containing all pins with blue LEDs.

Definition at line 51 of file ShiftRegisterOutBase.ipp.

◆ pins()

template<uint16_t N>
Array<pin_t, N> StaticSizeExtendedIOElement< N >::pins ( ) const
inlineinherited

Get an array containing all pins of the element.

Definition at line 24 of file StaticSizeExtendedIOElement.hpp.

◆ length()

template<uint16_t N>
static constexpr uint16_t StaticSizeExtendedIOElement< N >::length ( )
inlinestaticconstexprinherited

Definition at line 28 of file StaticSizeExtendedIOElement.hpp.

◆ beginAll()

void ExtendedIOElement::beginAll ( )
staticinherited

Initialize all extended IO elements.

Definition at line 21 of file ExtendedIOElement.cpp.

◆ pin()

pin_t ExtendedIOElement::pin ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.
Examples
1.First-Output.ino, and Toggle-LEDs.ino.

Definition at line 26 of file ExtendedIOElement.cpp.

◆ operator[]()

pin_t ExtendedIOElement::operator[] ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.


It is alias for ExtendedIOElement::pin.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.

Definition at line 41 of file ExtendedIOElement.cpp.

◆ getLength()

pin_t ExtendedIOElement::getLength ( ) const
inherited

Get the number of pins this IO element has.

Returns
The number of pins this IO element has.
Examples
1.AnalogReadSerial.ino, and 2.DigitalReadSerial.ino.

Definition at line 43 of file ExtendedIOElement.cpp.

◆ getEnd()

pin_t ExtendedIOElement::getEnd ( ) const
inherited

Get the largest global extended IO pin number that belongs to this extended IO element.

Definition at line 45 of file ExtendedIOElement.cpp.

◆ getStart()

pin_t ExtendedIOElement::getStart ( ) const
inherited

Get the smallest global extended IO pin number that belongs to this extended IO element.

Definition at line 47 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & ExtendedIOElement::getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 49 of file ExtendedIOElement.cpp.

Member Data Documentation

◆ latchPin

template<uint8_t N>
const pin_t ShiftRegisterOutBase< N >::latchPin
protectedinherited

Definition at line 137 of file ShiftRegisterOutBase.hpp.

◆ bitOrder

template<uint8_t N>
const uint8_t ShiftRegisterOutBase< N >::bitOrder
protectedinherited

Definition at line 138 of file ShiftRegisterOutBase.hpp.

◆ buffer

template<uint8_t N>
BitArray<N> ShiftRegisterOutBase< N >::buffer
protectedinherited

Definition at line 140 of file ShiftRegisterOutBase.hpp.

◆ dirty

template<uint8_t N>
bool ShiftRegisterOutBase< N >::dirty = true
protectedinherited

Definition at line 141 of file ShiftRegisterOutBase.hpp.

◆ start

const pin_t ExtendedIOElement::start
privateinherited

Definition at line 190 of file ExtendedIOElement.hpp.

◆ end

const pin_t ExtendedIOElement::end
privateinherited

Definition at line 191 of file ExtendedIOElement.hpp.

◆ offset

pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 192 of file ExtendedIOElement.hpp.

◆ elements

DoublyLinkedList< ExtendedIOElement > ExtendedIOElement::elements
staticprivateinherited

Definition at line 194 of file ExtendedIOElement.hpp.

◆ next

ExtendedIOElement * DoublyLinkable< ExtendedIOElement >::next
protectedinherited

Definition at line 301 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * DoublyLinkable< ExtendedIOElement >::previous
protectedinherited

Definition at line 302 of file LinkedList.hpp.


The documentation for this class was generated from the following files: