#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>
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.
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... | |
PinStatus_t | digitalRead (pin_t pin) override |
Read the digital state of the given input. More... | |
PinStatus_t | 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... | |
void | discardFirstReading (bool discardFirstReading_) |
Specify whether to discard the first analog reading after changing the address lines (enabled by default). More... | |
Protected 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... | |
Protected Attributes | |
const pin_t | analogPin |
const Array< pin_t, N > | addressPins |
const pin_t | enablePin |
bool | discardFirstReading_ = true |
Static Protected Attributes | |
static constexpr auto | MUX_ENABLED = LOW |
static constexpr auto | MUX_DISABLED = HIGH |
|
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. |
Definition at line 201 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. |
Definition at line 206 of file AnalogMultiplex.hpp.
|
inlineoverride |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 75 of file AnalogMultiplex.hpp.
|
inlineoverride |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 81 of file AnalogMultiplex.hpp.
|
override |
Read the digital state of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 211 of file AnalogMultiplex.hpp.
|
override |
Read the digital state of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 219 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 224 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 234 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 114 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 120 of file AnalogMultiplex.hpp.
|
override |
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.
Definition at line 239 of file AnalogMultiplex.hpp.
|
inlineoverride |
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Definition at line 133 of file AnalogMultiplex.hpp.
|
inlineoverride |
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Definition at line 139 of file AnalogMultiplex.hpp.
|
inline |
Specify whether to discard the first analog reading after changing the address lines (enabled by default).
Definition at line 145 of file AnalogMultiplex.hpp.
|
protected |
Write the pin number/address to the address pins of the multiplexer.
address | The address to select. |
Definition at line 249 of file AnalogMultiplex.hpp.
|
protected |
Select the correct address and enable the multiplexer.
address | The address to select. |
Definition at line 261 of file AnalogMultiplex.hpp.
|
protected |
Disable the multiplexer.
Definition at line 268 of file AnalogMultiplex.hpp.
|
protected |
Definition at line 150 of file AnalogMultiplex.hpp.
Definition at line 151 of file AnalogMultiplex.hpp.
|
protected |
Definition at line 152 of file AnalogMultiplex.hpp.
|
protected |
Definition at line 153 of file AnalogMultiplex.hpp.
|
staticconstexprprotected |
Definition at line 178 of file AnalogMultiplex.hpp.
|
staticconstexprprotected |
Definition at line 179 of file AnalogMultiplex.hpp.