Arduino Filters master
Filter library for Arduino
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
AnalogMultiplex< N > Class Template Reference

#include <AH/Hardware/ExtendedInputOutput/AnalogMultiplex.hpp>

Detailed Description

template<uint8_t N>
class AnalogMultiplex< N >

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.

Template Parameters
NThe number of address lines.

Definition at line 28 of file AnalogMultiplex.hpp.

+ Inheritance diagram for AnalogMultiplex< N >:
+ Collaboration diagram for AnalogMultiplex< N >:

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
 

Constructor & Destructor Documentation

◆ AnalogMultiplex()

AnalogMultiplex ( pin_t  analogPin,
const Array< pin_t, N > &  addressPins,
pin_t  enablePin = NO_PIN 
)
inline

Create a new AnalogMultiplex object on the given pins.

Parameters
analogPinThe analog input pin connected to the output of the multiplexer.
addressPinsAn array of the pins connected to the address lines of the multiplexer. (Labeled S0, S1, S2 ... in the datasheet.)
enablePinThe 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.

Member Function Documentation

◆ pinMode()

void pinMode ( pin_t  pin,
PinMode_t  mode 
)
override

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.

Note
This applies to all pins of this multiplexer.
This affects all pins of the multiplexer, because it has only a single common pin.
Parameters
pin(Unused)
modeThe new mode of the input pin: either INPUT or INPUT_PULLUP.

Definition at line 201 of file AnalogMultiplex.hpp.

◆ pinModeBuffered()

void pinModeBuffered ( pin_t  pin,
PinMode_t  mode 
)
override

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.

Note
This applies to all pins of this multiplexer.
This affects all pins of the multiplexer, because it has only a single common pin.
Parameters
pin(Unused)
modeThe new mode of the input pin: either INPUT or INPUT_PULLUP.

Definition at line 206 of file AnalogMultiplex.hpp.

◆ digitalWrite()

void digitalWrite ( pin_t  ,
PinStatus_t   
)
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.

◆ digitalWriteBuffered()

void digitalWriteBuffered ( pin_t  ,
PinStatus_t   
)
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.

◆ digitalRead()

PinStatus_t digitalRead ( pin_t  pin)
override

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Definition at line 211 of file AnalogMultiplex.hpp.

◆ digitalReadBuffered()

PinStatus_t digitalReadBuffered ( pin_t  pin)
override

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Definition at line 219 of file AnalogMultiplex.hpp.

◆ analogRead()

analog_t analogRead ( pin_t  pin)
override

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Definition at line 224 of file AnalogMultiplex.hpp.

◆ analogReadBuffered()

analog_t analogReadBuffered ( pin_t  pin)
override

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Definition at line 234 of file AnalogMultiplex.hpp.

◆ analogWrite()

void analogWrite ( pin_t  ,
analog_t   
)
inlineoverride

The analogWrite function is not implemented because writing an output to a multiplexer is not useful.

Definition at line 114 of file AnalogMultiplex.hpp.

◆ analogWriteBuffered()

void analogWriteBuffered ( pin_t  ,
analog_t   
)
inlineoverride

The analogWrite function is not implemented because writing an output to a multiplexer is not useful.

Definition at line 120 of file AnalogMultiplex.hpp.

◆ begin()

void begin
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.

◆ updateBufferedOutputs()

void updateBufferedOutputs ( )
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.

◆ updateBufferedInputs()

void updateBufferedInputs ( )
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.

◆ discardFirstReading()

void discardFirstReading ( bool  discardFirstReading_)
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.

◆ setMuxAddress()

void setMuxAddress ( uint8_t  address)
protected

Write the pin number/address to the address pins of the multiplexer.

Parameters
addressThe address to select.

Definition at line 249 of file AnalogMultiplex.hpp.

◆ prepareReading()

void prepareReading ( uint8_t  address)
protected

Select the correct address and enable the multiplexer.

Parameters
addressThe address to select.

Definition at line 261 of file AnalogMultiplex.hpp.

◆ afterReading()

void afterReading
protected

Disable the multiplexer.

Definition at line 268 of file AnalogMultiplex.hpp.

Member Data Documentation

◆ analogPin

const pin_t analogPin
protected

Definition at line 150 of file AnalogMultiplex.hpp.

◆ addressPins

const Array<pin_t, N> addressPins
protected

Definition at line 151 of file AnalogMultiplex.hpp.

◆ enablePin

const pin_t enablePin
protected

Definition at line 152 of file AnalogMultiplex.hpp.

◆ discardFirstReading_

bool discardFirstReading_ = true
protected

Definition at line 153 of file AnalogMultiplex.hpp.

◆ MUX_ENABLED

constexpr auto MUX_ENABLED = LOW
staticconstexprprotected

Definition at line 178 of file AnalogMultiplex.hpp.

◆ MUX_DISABLED

constexpr auto MUX_DISABLED = HIGH
staticconstexprprotected

Definition at line 179 of file AnalogMultiplex.hpp.


The documentation for this class was generated from the following file: