This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
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 Referenceabstract

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

#include <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 (UNUSED_PARAM pin_t pin, uint8_t mode) override
 Set the pin mode of the analog input pin. More...
 
void digitalWrite (UNUSED_PARAM pin_t pin, UNUSED_PARAM uint8_t val) 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 (UNUSED_PARAM pin_t pin, UNUSED_PARAM analog_t val) 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...
 
virtual void pinMode (pin_t pin, uint8_t mode)=0
 Set the mode of a given pin. More...
 
virtual void digitalWrite (pin_t pin, uint8_t state)=0
 Set the output of the given pin to the given state. More...
 
virtual void analogWrite (pin_t pin, analog_t val)=0
 Write an analog (or PWM) value to the given pin. 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 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.
Examples
1.AnalogReadSerial.ino, 1.First-Output.ino, 2.DigitalReadSerial.ino, and Toggle-LEDs.ino.

Definition at line 25 of file AnalogMultiplex.hpp.

Constructor & Destructor Documentation

◆ AnalogMultiplex()

template<uint8_t N>
AnalogMultiplex< 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() [1/2]

template<uint8_t N>
void AnalogMultiplex< N >::pinMode ( UNUSED_PARAM pin_t  pin,
uint8_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.
Examples
2.DigitalReadSerial.ino.

Definition at line 156 of file AnalogMultiplex.hpp.

◆ digitalWrite() [1/2]

template<uint8_t N>
void AnalogMultiplex< N >::digitalWrite ( UNUSED_PARAM pin_t  pin,
UNUSED_PARAM uint8_t  val 
)
inlineoverride

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

Definition at line 67 of file AnalogMultiplex.hpp.

◆ digitalRead()

template<uint8_t N>
int AnalogMultiplex< N >::digitalRead ( pin_t  pin)
overridevirtual

Read the digital state of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Examples
2.DigitalReadSerial.ino.

Definition at line 161 of file AnalogMultiplex.hpp.

◆ analogRead()

template<uint8_t N>
analog_t AnalogMultiplex< N >::analogRead ( pin_t  pin)
overridevirtual

Read the analog value of the given input.

Parameters
pinThe multiplexer's pin number to read from.

Implements ExtendedIOElement.

Examples
1.AnalogReadSerial.ino.

Definition at line 169 of file AnalogMultiplex.hpp.

◆ analogWrite() [1/2]

template<uint8_t N>
void AnalogMultiplex< N >::analogWrite ( UNUSED_PARAM pin_t  pin,
UNUSED_PARAM analog_t  val 
)
inlineoverride

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

Definition at line 90 of file AnalogMultiplex.hpp.

◆ begin()

template<uint8_t N>
void AnalogMultiplex< N >::begin ( )
overridevirtual

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

Implements ExtendedIOElement.

Examples
1.AnalogReadSerial.ino, 2.DigitalReadSerial.ino, and Toggle-LEDs.ino.

Definition at line 178 of file AnalogMultiplex.hpp.

◆ update()

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

◆ setMuxAddress()

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

◆ prepareReading()

template<uint8_t N>
void AnalogMultiplex< N >::prepareReading ( uint8_t  address)
private

Select the correct address and enable the multiplexer.

Parameters
addressThe address to select.

Definition at line 200 of file AnalogMultiplex.hpp.

◆ afterReading()

template<uint8_t N>
void AnalogMultiplex< N >::afterReading ( )
private

Disable the multiplexer.

Definition at line 207 of file AnalogMultiplex.hpp.

◆ pins()

Array<pin_t, N> StaticSizeExtendedIOElement< N >::pins ( ) const
inlineinherited

Get an array containing all pins of the element.

Examples
1.AnalogReadSerial.ino, and 2.DigitalReadSerial.ino.

Definition at line 24 of file StaticSizeExtendedIOElement.hpp.

◆ length()

static constexpr uint16_t StaticSizeExtendedIOElement< N >::length ( )
inlinestaticconstexprinherited
Examples
Toggle-LEDs.ino.

Definition at line 28 of file StaticSizeExtendedIOElement.hpp.

◆ pinMode() [2/2]

virtual void ExtendedIOElement::pinMode ( pin_t  pin,
uint8_t  mode 
)
pure virtualinherited

Set the mode of a given pin.

Note
This function might not be implemented by all subclasses.
Some extended IO types, such as shift registers, can only be used as outputs.
On others, it might be implemented, but it could impact all pins of the IO element. For example, enabling the internal pull-up resistor on an analog multiplexer affects all pins of the mux.
Parameters
pinThe (zero-based) pin of this IO element.
modeThe mode to set the pin to (e.g. INPUT, OUTPUT or INPUT_PULLUP).

◆ digitalWrite() [2/2]

virtual void ExtendedIOElement::digitalWrite ( pin_t  pin,
uint8_t  state 
)
pure virtualinherited

Set the output of the given pin to the given state.

Parameters
pinThe (zero-based) pin of this IO element.
stateThe new state to set the pin to.

Implemented in ShiftRegisterOutBase< N >, and MAX7219.

◆ analogWrite() [2/2]

virtual void ExtendedIOElement::analogWrite ( pin_t  pin,
analog_t  val 
)
pure virtualinherited

Write an analog (or PWM) value to the given pin.

Parameters
pinThe (zero-based) pin of this IO element.
valThe new analog value to set the pin to.

Implemented in MAX7219, and ShiftRegisterOutBase< N >.

◆ beginAll()

void ExtendedIOElement::beginAll ( )
staticinherited

Initialize all extended IO elements.

Definition at line 21 of file ExtendedIOElement.cpp.

◆ pin()

pin_t ExtendedIOElement::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.
Examples
1.First-Output.ino, and Toggle-LEDs.ino.

Definition at line 26 of file ExtendedIOElement.cpp.

◆ operator[]()

pin_t ExtendedIOElement::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 41 of file ExtendedIOElement.cpp.

◆ getLength()

pin_t ExtendedIOElement::getLength ( ) const
inherited

Get the number of pins this IO element has.

Returns
The number of pins this IO element has.
Examples
1.AnalogReadSerial.ino, and 2.DigitalReadSerial.ino.

Definition at line 43 of file ExtendedIOElement.cpp.

◆ getEnd()

pin_t ExtendedIOElement::getEnd ( ) const
inherited

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

Definition at line 45 of file ExtendedIOElement.cpp.

◆ getStart()

pin_t ExtendedIOElement::getStart ( ) const
inherited

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

Definition at line 47 of file ExtendedIOElement.cpp.

◆ getAll()

DoublyLinkedList< ExtendedIOElement > & ExtendedIOElement::getAll ( )
staticinherited

Get the list of all Extended IO elements.

Definition at line 49 of file ExtendedIOElement.cpp.

Member Data Documentation

◆ analogPin

template<uint8_t N>
const pin_t AnalogMultiplex< N >::analogPin
private

Definition at line 106 of file AnalogMultiplex.hpp.

◆ addressPins

template<uint8_t N>
const Array<pin_t, N> AnalogMultiplex< N >::addressPins
private

Definition at line 107 of file AnalogMultiplex.hpp.

◆ enablePin

template<uint8_t N>
const pin_t AnalogMultiplex< N >::enablePin
private

Definition at line 108 of file AnalogMultiplex.hpp.

◆ MUX_ENABLED

template<uint8_t N>
constexpr static uint8_t AnalogMultiplex< N >::MUX_ENABLED = LOW
staticconstexprprivate

Definition at line 133 of file AnalogMultiplex.hpp.

◆ MUX_DISABLED

template<uint8_t N>
constexpr static uint8_t AnalogMultiplex< N >::MUX_DISABLED = HIGH
staticconstexprprivate

Definition at line 134 of file AnalogMultiplex.hpp.

◆ start

const pin_t ExtendedIOElement::start
privateinherited

Definition at line 190 of file ExtendedIOElement.hpp.

◆ end

const pin_t ExtendedIOElement::end
privateinherited

Definition at line 191 of file ExtendedIOElement.hpp.

◆ offset

pin_t ExtendedIOElement::offset = NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS
staticprivateinherited

Definition at line 192 of file ExtendedIOElement.hpp.

◆ elements

DoublyLinkedList< ExtendedIOElement > ExtendedIOElement::elements
staticprivateinherited

Definition at line 194 of file ExtendedIOElement.hpp.

◆ next

ExtendedIOElement * DoublyLinkable< ExtendedIOElement >::next
protectedinherited

Definition at line 301 of file LinkedList.hpp.

◆ previous

ExtendedIOElement * DoublyLinkable< ExtendedIOElement >::previous
protectedinherited

Definition at line 302 of file LinkedList.hpp.


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