Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
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 AH::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 25 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.
 
void pinMode (pin_t pin, PinMode_t mode) override
 Set the pin mode of the analog input pin.
 
void pinModeBuffered (pin_t pin, PinMode_t mode) override
 Set the pin mode of the analog input pin.
 
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.
 
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.
 
PinStatus_t digitalRead (pin_t pin) override
 Read the digital state of the given input.
 
PinStatus_t digitalReadBuffered (pin_t pin) override
 Read the digital state of the given input.
 
analog_t analogRead (pin_t pin) override
 Read the analog value of the given input.
 
analog_t analogReadBuffered (pin_t pin) override
 Read the analog value of the given input.
 
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.
 
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.
 
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
 

Constructor & Destructor Documentation

◆ AnalogMultiplex()

template<uint8_t N>
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 41 of file AnalogMultiplex.hpp.

Member Function Documentation

◆ pinMode()

template<uint8_t N>
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 198 of file AnalogMultiplex.hpp.

◆ pinModeBuffered()

template<uint8_t N>
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 203 of file AnalogMultiplex.hpp.

◆ digitalWrite()

template<uint8_t N>
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 72 of file AnalogMultiplex.hpp.

◆ digitalWriteBuffered()

template<uint8_t N>
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 78 of file AnalogMultiplex.hpp.

◆ digitalRead()

template<uint8_t N>
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 208 of file AnalogMultiplex.hpp.

◆ digitalReadBuffered()

template<uint8_t N>
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 216 of file AnalogMultiplex.hpp.

◆ analogRead()

template<uint8_t N>
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 221 of file AnalogMultiplex.hpp.

◆ analogReadBuffered()

template<uint8_t N>
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 231 of file AnalogMultiplex.hpp.

◆ analogWrite()

template<uint8_t N>
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 111 of file AnalogMultiplex.hpp.

◆ analogWriteBuffered()

template<uint8_t N>
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 117 of file AnalogMultiplex.hpp.

◆ begin()

template<uint8_t N>
void begin ( )
override

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.

◆ updateBufferedOutputs()

template<uint8_t N>
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 130 of file AnalogMultiplex.hpp.

◆ updateBufferedInputs()

template<uint8_t N>
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 136 of file AnalogMultiplex.hpp.

◆ discardFirstReading()

template<uint8_t N>
void discardFirstReading ( bool discardFirstReading_)
inline

Specify whether to discard the first analog reading after changing the address lines (enabled by default).

Definition at line 142 of file AnalogMultiplex.hpp.

◆ setMuxAddress()

template<uint8_t N>
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 246 of file AnalogMultiplex.hpp.

◆ prepareReading()

template<uint8_t N>
void prepareReading ( uint8_t address)
protected

Select the correct address and enable the multiplexer.

Parameters
addressThe address to select.

Definition at line 258 of file AnalogMultiplex.hpp.

◆ afterReading()

template<uint8_t N>
void afterReading ( )
protected

Disable the multiplexer.

Definition at line 265 of file AnalogMultiplex.hpp.

Member Data Documentation

◆ analogPin

template<uint8_t N>
const pin_t analogPin
protected

Definition at line 147 of file AnalogMultiplex.hpp.

◆ addressPins

template<uint8_t N>
const Array<pin_t, N> addressPins
protected

Definition at line 148 of file AnalogMultiplex.hpp.

◆ enablePin

template<uint8_t N>
const pin_t enablePin
protected

Definition at line 149 of file AnalogMultiplex.hpp.

◆ discardFirstReading_

template<uint8_t N>
bool discardFirstReading_ = true
protected

Definition at line 150 of file AnalogMultiplex.hpp.

◆ MUX_ENABLED

template<uint8_t N>
constexpr auto MUX_ENABLED = LOW
staticconstexprprotected

Definition at line 175 of file AnalogMultiplex.hpp.

◆ MUX_DISABLED

template<uint8_t N>
constexpr auto MUX_DISABLED = HIGH
staticconstexprprotected

Definition at line 176 of file AnalogMultiplex.hpp.


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