A class for reading multiplexed analog inputs. More...
#include <AnalogMultiplex.hpp>
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, uint8_t mode) override |
| Set the pin mode of the analog input pin. More... | |
| void | digitalWrite (pin_t, uint8_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... | |
| analog_t | analogRead (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 | begin () override |
| Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode. More... | |
| void | update () 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 DoublyLinkedList< ExtendedIOElement > & | getAll () |
| Get the list of all Extended IO elements. More... | |
Protected Attributes | |
| ExtendedIOElement * | next |
| ExtendedIOElement * | previous |
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 uint8_t | MUX_ENABLED = LOW |
| constexpr static uint8_t | MUX_DISABLED = HIGH |
| static pin_t | offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS |
| static DoublyLinkedList< ExtendedIOElement > | elements |
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.
|
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.
|
overridevirtual |
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 AH::ExtendedIOElement.
Definition at line 159 of file AnalogMultiplex.hpp.
|
inlineoverridevirtual |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Implements AH::ExtendedIOElement.
Definition at line 70 of file AnalogMultiplex.hpp.
|
overridevirtual |
Read the digital state of the given input.
| pin | The multiplexer's pin number to read from. |
Implements AH::ExtendedIOElement.
Definition at line 164 of file AnalogMultiplex.hpp.
|
overridevirtual |
Read the analog value of the given input.
| pin | The multiplexer's pin number to read from. |
Implements AH::ExtendedIOElement.
Definition at line 172 of file AnalogMultiplex.hpp.
|
inlineoverridevirtual |
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Implements AH::ExtendedIOElement.
Definition at line 93 of file AnalogMultiplex.hpp.
|
overridevirtual |
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.
Implements AH::ExtendedIOElement.
Definition at line 181 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 AH::ExtendedIOElement.
Definition at line 106 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 191 of file AnalogMultiplex.hpp.
|
private |
Select the correct address and enable the multiplexer.
| address | The address to select. |
Definition at line 203 of file AnalogMultiplex.hpp.
|
private |
Disable the multiplexer.
Definition at line 210 of file AnalogMultiplex.hpp.
|
inlineinherited |
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 23 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 28 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 43 of file ExtendedIOElement.cpp.
|
inherited |
Get the number of pins this IO element has.
Definition at line 45 of file ExtendedIOElement.cpp.
|
inherited |
Get the largest global extended IO pin number that belongs to this extended IO element.
Definition at line 47 of file ExtendedIOElement.cpp.
|
inherited |
Get the smallest global extended IO pin number that belongs to this extended IO element.
Definition at line 49 of file ExtendedIOElement.cpp.
|
staticinherited |
Get the list of all Extended IO elements.
Definition at line 51 of file ExtendedIOElement.cpp.
|
private |
Definition at line 109 of file AnalogMultiplex.hpp.
|
private |
Definition at line 110 of file AnalogMultiplex.hpp.
|
private |
Definition at line 111 of file AnalogMultiplex.hpp.
|
staticconstexprprivate |
Definition at line 136 of file AnalogMultiplex.hpp.
|
staticconstexprprivate |
Definition at line 137 of file AnalogMultiplex.hpp.
|
privateinherited |
Definition at line 193 of file ExtendedIOElement.hpp.
|
privateinherited |
Definition at line 194 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 195 of file ExtendedIOElement.hpp.
|
staticprivateinherited |
Definition at line 197 of file ExtendedIOElement.hpp.
|
protectedinherited |
Definition at line 305 of file LinkedList.hpp.
|
protectedinherited |
Definition at line 306 of file LinkedList.hpp.
1.8.16