A class for reading multiplexed analog inputs. More...
#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
 Inheritance diagram for AnalogMultiplex< N >:
 Collaboration diagram for AnalogMultiplex< N >:Public Types | |
| using | Mutex = typename std::conditional< false, DefaultMutEx, EmptyMutex >::type | 
| using | LockGuard = typename std::conditional< false, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type | 
Public Member Functions | |
| AnalogMultiplex (pin_t analogPin, const Array< pin_t, N > &addressPins, pin_t enablePin=NO_PIN) | |
| Create a new AnalogMultiplex object on the given pins.  More... | |
| void | pinMode (pin_t pin, PinMode_t mode) override | 
| Set the pin mode of the analog input pin.  More... | |
| void | pinModeBuffered (pin_t pin, PinMode_t mode) override | 
| Set the pin mode of the analog input pin.  More... | |
| void | digitalWrite (pin_t, PinStatus_t) override __attribute__((deprecated)) | 
| The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.  More... | |
| void | digitalWriteBuffered (pin_t, PinStatus_t) override __attribute__((deprecated)) | 
| The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.  More... | |
| int | digitalRead (pin_t pin) override | 
| Read the digital state of the given input.  More... | |
| int | digitalReadBuffered (pin_t pin) override | 
| Read the digital state of the given input.  More... | |
| analog_t | analogRead (pin_t pin) override | 
| Read the analog value of the given input.  More... | |
| analog_t | analogReadBuffered (pin_t pin) override | 
| Read the analog value of the given input.  More... | |
| void | analogWrite (pin_t, analog_t) override __attribute__((deprecated)) | 
| The analogWrite function is not implemented because writing an output to a multiplexer is not useful.  More... | |
| void | analogWriteBuffered (pin_t, analog_t) override __attribute__((deprecated)) | 
| The analogWrite function is not implemented because writing an output to a multiplexer is not useful.  More... | |
| void | begin () override | 
| Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.  More... | |
| void | updateBufferedOutputs () override | 
| No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.  More... | |
| void | updateBufferedInputs () override | 
| No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.  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 void | updateAllBufferedOutputs () | 
| Write the internal states to the physical outputs for all extended IO elements.  More... | |
| static void | updateAllBufferedInputs () | 
| Read the physical state into the input buffers for all extended IO elements.  More... | |
| static DoublyLinkedList< ExtendedIOElement > & | getAll () | 
| Get the list of all Extended IO elements.  More... | |
| static Mutex & | getMutex () | 
Protected Attributes | |
| ExtendedIOElement * | next | 
| ExtendedIOElement * | previous | 
Static Protected Attributes | |
| static DoublyLinkedList< ExtendedIOElement > | updatables | 
| static Mutex | mutex | 
Private Member Functions | |
| void | setMuxAddress (uint8_t address) | 
| Write the pin number/address to the address pins of the multiplexer.  More... | |
| void | prepareReading (uint8_t address) | 
| Select the correct address and enable the multiplexer.  More... | |
| void | afterReading () | 
| Disable the multiplexer.  More... | |
Private Attributes | |
| const pin_t | analogPin | 
| const Array< pin_t, N > | addressPins | 
| const pin_t | enablePin | 
| const pin_t | start | 
| const pin_t | end | 
Static Private Attributes | |
| constexpr static auto | MUX_ENABLED = LOW | 
| constexpr static auto | MUX_DISABLED = HIGH | 
| static pin_t | offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS | 
Main initialization and updating methods | |
| static void | applyToAll (const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args) | 
| static void | applyToAll (void(Derived::*method)(Args &&...), Args &&... args) | 
Enabling and disabling updatables | |
| void | enable (const LockGuard &lock) | 
| Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.  More... | |
| void | enable () | 
| Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.  More... | |
| void | disable (const LockGuard &lock) | 
| Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.  More... | |
| void | disable () | 
| Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.  More... | |
| bool | isEnabled (const LockGuard &) const | 
| Check if this updatable is enabled.  More... | |
| bool | isEnabled () | 
| Check if this updatable is enabled.  More... | |
| void | moveDown (const LockGuard &) | 
| Move down this element in the list.  More... | |
| void | moveDown () | 
| Move down this element in the list.  More... | |
| static void | enable (UpdatableCRTP *element) | 
| Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.  More... | |
| static void | enable (UpdatableCRTP &element) | 
| Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.  More... | |
| static void | enable (U(&array)[N]) | 
| Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.  More... | |
| static void | disable (UpdatableCRTP *element) | 
| Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.  More... | |
| static void | disable (UpdatableCRTP &element) | 
| Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.  More... | |
| static void | disable (U(&array)[N]) | 
| Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.  More... | |
A class for reading multiplexed analog inputs.
Supports 74HC4067, 74HC4051, etc.
You can use many multiplexers on the same address lines if each of the multiplexers has a different enable line.
| N | The number of address lines. | 
Definition at line 28 of file AnalogMultiplex.hpp.
      
  | 
  inherited | 
Definition at line 36 of file Updatable.hpp.
      
  | 
  inherited | 
Definition at line 38 of file Updatable.hpp.
      
  | 
  inline | 
Create a new AnalogMultiplex object on the given pins.
| analogPin | The analog input pin connected to the output of the multiplexer. | 
| addressPins | An array of the pins connected to the address lines of the multiplexer. (Labeled S0, S1, S2 ... in the datasheet.) | 
| enablePin | The digital output pin connected to the enable pin of the multiplexer. (Labeled Ē in the datasheet.)  If you don't need the enable pin, you can use NO_PIN, which is the default.  | 
Definition at line 44 of file AnalogMultiplex.hpp.
Set the pin mode of the analog input pin.
 This allows you to enable the internal pull-up resistor, for use with buttons or open-collector outputs.
| pin | (Unused) | 
| mode | The new mode of the input pin: either INPUT or INPUT_PULLUP. | 
Reimplemented from ExtendedIOElement.
Definition at line 192 of file AnalogMultiplex.hpp.
Set the pin mode of the analog input pin.
 This allows you to enable the internal pull-up resistor, for use with buttons or open-collector outputs.
| pin | (Unused) | 
| mode | The new mode of the input pin: either INPUT or INPUT_PULLUP. | 
Implements ExtendedIOElement.
Definition at line 197 of file AnalogMultiplex.hpp.
      
  | 
  inlineoverridevirtual | 
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Reimplemented from ExtendedIOElement.
Definition at line 75 of file AnalogMultiplex.hpp.
      
  | 
  inlineoverridevirtual | 
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Implements ExtendedIOElement.
Definition at line 81 of file AnalogMultiplex.hpp.
      
  | 
  overridevirtual | 
Read the digital state of the given input.
| pin | The multiplexer's pin number to read from. | 
Reimplemented from ExtendedIOElement.
Definition at line 202 of file AnalogMultiplex.hpp.
      
  | 
  overridevirtual | 
Read the digital state of the given input.
| pin | The multiplexer's pin number to read from. | 
Implements ExtendedIOElement.
Definition at line 210 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
| pin | The multiplexer's pin number to read from. | 
Reimplemented from ExtendedIOElement.
Definition at line 215 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
| pin | The multiplexer's pin number to read from. | 
Implements ExtendedIOElement.
Definition at line 224 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Reimplemented from ExtendedIOElement.
Definition at line 114 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Implements ExtendedIOElement.
Definition at line 120 of file AnalogMultiplex.hpp.
      
  | 
  overridevirtual | 
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.
Implements ExtendedIOElement.
Definition at line 229 of file AnalogMultiplex.hpp.
      
  | 
  inlineoverridevirtual | 
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Implements ExtendedIOElement.
Definition at line 133 of file AnalogMultiplex.hpp.
      
  | 
  inlineoverridevirtual | 
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Implements ExtendedIOElement.
Definition at line 139 of file AnalogMultiplex.hpp.
      
  | 
  private | 
Write the pin number/address to the address pins of the multiplexer.
| address | The address to select. | 
Definition at line 239 of file AnalogMultiplex.hpp.
      
  | 
  private | 
Select the correct address and enable the multiplexer.
| address | The address to select. | 
Definition at line 251 of file AnalogMultiplex.hpp.
      
  | 
  private | 
Disable the multiplexer.
Definition at line 258 of file AnalogMultiplex.hpp.
Get an array containing all pins of the element.
Definition at line 27 of file StaticSizeExtendedIOElement.hpp.
      
  | 
  inlinestaticconstexprinherited | 
Definition at line 31 of file StaticSizeExtendedIOElement.hpp.
      
  | 
  staticinherited | 
Initialize all extended IO elements.
Definition at line 20 of file ExtendedIOElement.cpp.
      
  | 
  staticinherited | 
Write the internal states to the physical outputs for all extended IO elements.
Definition at line 24 of file ExtendedIOElement.cpp.
      
  | 
  staticinherited | 
Read the physical state into the input buffers for all extended IO elements.
Definition at line 28 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
| pin | The zero-based physical pin number of this IO element. | 
Definition at line 32 of file ExtendedIOElement.cpp.
Get the extended IO pin number of a given physical pin of this extended IO element.
 It is alias for ExtendedIOElement::pin. 
| pin | The zero-based physical pin number of this IO element. | 
Definition at line 47 of file ExtendedIOElement.cpp.
      
  | 
  inherited | 
Get the number of pins this IO element has.
Definition at line 49 of file ExtendedIOElement.cpp.
      
  | 
  inherited | 
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 51 of file ExtendedIOElement.cpp.
      
  | 
  inherited | 
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 53 of file ExtendedIOElement.cpp.
      
  | 
  staticinherited | 
Get the list of all Extended IO elements.
Definition at line 55 of file ExtendedIOElement.cpp.
      
  | 
  inlinestaticinherited | 
Definition at line 79 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Definition at line 85 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Definition at line 93 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 106 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 115 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 144 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 146 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.
Definition at line 149 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 119 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 128 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 155 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 157 of file Updatable.hpp.
      
  | 
  inlinestaticinherited | 
Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.
Definition at line 160 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Check if this updatable is enabled.
Definition at line 136 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Check if this updatable is enabled.
Definition at line 141 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Move down this element in the list.
Definition at line 166 of file Updatable.hpp.
      
  | 
  inlineinherited | 
Move down this element in the list.
Definition at line 168 of file Updatable.hpp.
      
  | 
  private | 
Definition at line 142 of file AnalogMultiplex.hpp.
Definition at line 143 of file AnalogMultiplex.hpp.
      
  | 
  private | 
Definition at line 144 of file AnalogMultiplex.hpp.
      
  | 
  staticconstexprprivate | 
Definition at line 169 of file AnalogMultiplex.hpp.
      
  | 
  staticconstexprprivate | 
Definition at line 170 of file AnalogMultiplex.hpp.
      
  | 
  privateinherited | 
Definition at line 260 of file ExtendedIOElement.hpp.
      
  | 
  privateinherited | 
Definition at line 261 of file ExtendedIOElement.hpp.
      
  | 
  staticprivateinherited | 
Definition at line 262 of file ExtendedIOElement.hpp.
      
  | 
  staticprotectedinherited | 
Definition at line 173 of file Updatable.hpp.
      
  | 
  staticprotectedinherited | 
Definition at line 174 of file Updatable.hpp.
      
  | 
  protectedinherited | 
Definition at line 323 of file LinkedList.hpp.
      
  | 
  protectedinherited | 
Definition at line 324 of file LinkedList.hpp.