#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 25 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. | |
void | pinMode (pin_int_t pin, PinMode_t mode) override |
Set the pin mode of the analog input pin. | |
void | pinModeBuffered (pin_int_t pin, PinMode_t mode) override |
Set the pin mode of the analog input pin. | |
void | digitalWrite (pin_int_t, PinStatus_t) override __attribute__((deprecated)) |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful. | |
void | digitalWriteBuffered (pin_int_t, PinStatus_t) override __attribute__((deprecated)) |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful. | |
PinStatus_t | digitalRead (pin_int_t pin) override |
Read the digital state of the given input. | |
PinStatus_t | digitalReadBuffered (pin_int_t pin) override |
Read the digital state of the given input. | |
analog_t | analogRead (pin_int_t pin) override |
Read the analog value of the given input. | |
analog_t | analogReadBuffered (pin_int_t pin) override |
Read the analog value of the given input. | |
void | analogWrite (pin_int_t, analog_t) override __attribute__((deprecated)) |
The analogWrite function is not implemented because writing an output to a multiplexer is not useful. | |
void | analogWriteBuffered (pin_int_t, analog_t) override __attribute__((deprecated)) |
The analogWrite function is not implemented because writing an output to a multiplexer is not useful. | |
void | begin () override |
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode. | |
void | updateBufferedOutputs () override |
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead. | |
void | updateBufferedInputs () override |
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead. | |
void | discardFirstReading (bool discardFirstReading_) |
Specify whether to discard the first analog reading after changing the address lines (enabled by default). | |
Protected Member Functions | |
void | setMuxAddress (uint8_t address) |
Write the pin number/address to the address pins of the multiplexer. | |
void | prepareReading (uint8_t address) |
Select the correct address and enable the multiplexer. | |
void | afterReading () |
Disable the multiplexer. | |
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 41 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 198 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 203 of file AnalogMultiplex.hpp.
|
inlineoverride |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 72 of file AnalogMultiplex.hpp.
|
inlineoverride |
The digitalWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 78 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 208 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 216 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 221 of file AnalogMultiplex.hpp.
Read the analog value of the given input.
pin | The multiplexer's pin number to read from. |
Definition at line 231 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 111 of file AnalogMultiplex.hpp.
The analogWrite function is not implemented because writing an output to a multiplexer is not useful.
Definition at line 117 of file AnalogMultiplex.hpp.
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.
Definition at line 236 of file AnalogMultiplex.hpp.
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Definition at line 130 of file AnalogMultiplex.hpp.
No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.
Definition at line 136 of file AnalogMultiplex.hpp.
Specify whether to discard the first analog reading after changing the address lines (enabled by default).
Definition at line 142 of file AnalogMultiplex.hpp.
Write the pin number/address to the address pins of the multiplexer.
address | The address to select. |
Definition at line 246 of file AnalogMultiplex.hpp.
Select the correct address and enable the multiplexer.
address | The address to select. |
Definition at line 258 of file AnalogMultiplex.hpp.
Disable the multiplexer.
Definition at line 265 of file AnalogMultiplex.hpp.
Definition at line 147 of file AnalogMultiplex.hpp.
Definition at line 148 of file AnalogMultiplex.hpp.
Definition at line 149 of file AnalogMultiplex.hpp.
Definition at line 150 of file AnalogMultiplex.hpp.
Definition at line 175 of file AnalogMultiplex.hpp.
Definition at line 176 of file AnalogMultiplex.hpp.