Control Surface  1.1.0
MIDI Control Surface library for Arduino
ShiftRegisterOut.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include "ShiftRegisterOutBase.hpp"
9 
11 #include <Arduino.h> // MSBFIRST
13 
15 
16 /**
17  * @brief A class for serial-in/parallel-out shift registers,
18  * like the 74HC595.
19  *
20  * @ingroup AH_ExtIO
21  */
22 template <uint8_t N>
24  public:
26 
27  /**
28  * @brief Create a new ShiftRegisterOut object with a shift register
29  * connected to the given pins, with a given bit order,
30  * and a given number of outputs.
31  *
32  * Multiple shift registers can be cascaded by connecting the serial output
33  * of the first one to the input of the second one:
34  * ```
35  * clockPin >───────────┬──────────────────────┬───────── ⋯
36  * ┏━━━━━━━┷━━━━━━━┓ ┏━━━━━━━┷━━━━━━━┓
37  * ┃ SH_CP ┃ ┃ SH_CP ┃
38  * dataPin >───┨ DS Q7S ┠──────┨ DS Q7S ┠─ ⋯
39  * ┃ ST_CP ┃ ┃ ST_CP ┃
40  * ┗━━━━━━━┯━━━━━━━┛ ┗━━━━━━━┯━━━━━━━┛
41  * latchPin >───────────┴──────────────────────┴───────── ⋯
42  * ```
43  *
44  * @param dataPin
45  * The digital output pin connected to the serial data input (DS or
46  * SER) of the shift register.
47  * @param clockPin
48  * The digital output pin connected to the clock input (SH_CP or
49  * SRCLK) of the shift register.
50  * @param latchPin
51  * The digital output pin connected to the latch pin (ST_CP or
52  * RCLK) of the shift register.
53  * @param bitOrder
54  * Either `MSBFIRST` (most significant bit first) or `LSBFIRST`
55  * (least significant bit first).
56  */
57  ShiftRegisterOut(pin_t dataPin, pin_t clockPin, pin_t latchPin,
58  BitOrder_t bitOrder = MSBFIRST);
59 
60  /**
61  * @brief Initialize the shift register.
62  * Set the data and clock pins to output mode,
63  * and set all shift register outputs to `LOW`.
64  */
65  void begin() override;
66 
67  /**
68  * @brief Write the state buffer to the physical outputs.
69  */
70  void update() override;
71 
72  private:
73  const pin_t dataPin;
74  const pin_t clockPin;
75 };
76 
78 
79 #include "ShiftRegisterOut.ipp"
80 
Warnings.hpp
AH::ShiftRegisterOut::clockPin
const pin_t clockPin
Definition: ShiftRegisterOut.hpp:74
AH::ShiftRegisterOutBase
A class for serial-in/parallel-out shift registers, like the 74HC595.
Definition: ShiftRegisterOutBase.hpp:25
AH::ShiftRegisterOut
A class for serial-in/parallel-out shift registers, like the 74HC595.
Definition: ShiftRegisterOut.hpp:23
AH::ShiftRegisterOut::dataPin
const pin_t dataPin
Definition: ShiftRegisterOut.hpp:73
ShiftRegisterOut.ipp
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::ShiftRegisterOut::BitOrder_t
typename ShiftRegisterOutBase< N >::BitOrder_t BitOrder_t
Definition: ShiftRegisterOut.hpp:25
AH_DIAGNOSTIC_EXTERNAL_HEADER
#define AH_DIAGNOSTIC_EXTERNAL_HEADER()
Definition: Warnings.hpp:18
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
AH::ShiftRegisterOutBase::BitOrder_t
uint8_t BitOrder_t
Definition: ShiftRegisterOutBase.hpp:30
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10