Control Surface  1.1.1
MIDI Control Surface library for Arduino
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AnalogMultiplex< N > Class Template Reference

A class for reading multiplexed analog inputs. More...

#include <AH/Hardware/ExtendedInputOutput/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, 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

ExtendedIOElementnext
 
ExtendedIOElementprevious
 

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< ExtendedIOElementelements
 

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 28 of file AnalogMultiplex.hpp.

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,
uint8_t  mode 
)
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.

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.

Implements ExtendedIOElement.

Definition at line 159 of file AnalogMultiplex.hpp.

◆ digitalWrite()

void digitalWrite ( pin_t  ,
uint8_t   
)
inlineoverridevirtual

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

Implements ExtendedIOElement.

Definition at line 70 of file AnalogMultiplex.hpp.

◆ digitalRead()

int digitalRead ( pin_t  pin)
overridevirtual

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Definition at line 164 of file AnalogMultiplex.hpp.

◆ analogRead()

analog_t analogRead ( pin_t  pin)
overridevirtual

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Definition at line 172 of file AnalogMultiplex.hpp.

◆ analogWrite()

void analogWrite ( pin_t  ,
analog_t   
)
inlineoverridevirtual

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

Implements ExtendedIOElement.

Definition at line 93 of file AnalogMultiplex.hpp.

◆ begin()

void begin ( )
overridevirtual

Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.

Implements ExtendedIOElement.

Definition at line 181 of file AnalogMultiplex.hpp.

◆ update()

void update ( )
inlineoverridevirtual

No periodic updating of the state is necessary, all actions are carried out when the user calls analogRead or digitalRead.

Implements ExtendedIOElement.

Definition at line 106 of file AnalogMultiplex.hpp.

◆ setMuxAddress()

void setMuxAddress ( uint8_t  address)
private

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

Parameters
addressThe address to select.

Definition at line 191 of file AnalogMultiplex.hpp.

◆ prepareReading()

void prepareReading ( uint8_t  address)
private

Select the correct address and enable the multiplexer.

Parameters
addressThe address to select.

Definition at line 203 of file AnalogMultiplex.hpp.

◆ afterReading()

void afterReading ( )
private

Disable the multiplexer.

Definition at line 210 of file AnalogMultiplex.hpp.

◆ pins()

Array<pin_t, N> pins ( ) const
inlineinherited

Get an array containing all pins of the element.

Definition at line 27 of file StaticSizeExtendedIOElement.hpp.

◆ length()

static constexpr uint16_t length ( )
inlinestaticconstexprinherited

Definition at line 31 of file StaticSizeExtendedIOElement.hpp.

◆ beginAll()

void beginAll ( )
staticinherited

Initialize all extended IO elements.

Definition at line 23 of file ExtendedIOElement.cpp.

◆ pin()

pin_t pin ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.

Definition at line 28 of file ExtendedIOElement.cpp.

◆ operator[]()

pin_t operator[] ( pin_t  pin) const
inherited

Get the extended IO pin number of a given physical pin of this extended IO element.


It is alias for ExtendedIOElement::pin.

Parameters
pinThe zero-based physical pin number of this IO element.
Returns
The global, unique extended IO pin number for the given pin.

Definition at line 43 of file ExtendedIOElement.cpp.

◆ getLength()

pin_t getLength ( ) const
inherited

Get the number of pins this IO element has.

Returns
The number of pins this IO element has.

Definition at line 45 of file ExtendedIOElement.cpp.

◆ getEnd()

pin_t getEnd ( ) const
inherited

Get the largest global extended IO pin number that belongs to this extended IO element.

Definition at line 47 of file ExtendedIOElement.cpp.

◆ getStart()

pin_t getStart ( ) const
inherited

Get the smallest global extended IO pin number that belongs to this extended IO element.

Definition at line 49 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 51 of file ExtendedIOElement.cpp.

Member Data Documentation

◆ analogPin

const pin_t analogPin
private

Definition at line 109 of file AnalogMultiplex.hpp.

◆ addressPins

const Array<pin_t, N> addressPins
private

Definition at line 110 of file AnalogMultiplex.hpp.

◆ enablePin

const pin_t enablePin
private

Definition at line 111 of file AnalogMultiplex.hpp.

◆ MUX_ENABLED

constexpr static uint8_t MUX_ENABLED = LOW
staticconstexprprivate

Definition at line 136 of file AnalogMultiplex.hpp.

◆ MUX_DISABLED

constexpr static uint8_t MUX_DISABLED = HIGH
staticconstexprprivate

Definition at line 137 of file AnalogMultiplex.hpp.

◆ start

const pin_t start
privateinherited

Definition at line 193 of file ExtendedIOElement.hpp.

◆ end

const pin_t end
privateinherited

Definition at line 194 of file ExtendedIOElement.hpp.

◆ offset

pin_t offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 195 of file ExtendedIOElement.hpp.

◆ elements

DoublyLinkedList< ExtendedIOElement > elements
staticprivateinherited

Definition at line 197 of file ExtendedIOElement.hpp.

◆ next

ExtendedIOElement * next
protectedinherited

Definition at line 305 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * previous
protectedinherited

Definition at line 306 of file LinkedList.hpp.


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