1.AnalogReadSerial
This is an example of the AnalogMultiplex class. It prints the values of all 16 inputs of a multiplexers to the serial monitor.
- Boards:
- AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Connections
- A0: CD74HC4067 signal pin ("common input/output")
- 3: CD74HC4067 address pin S0
- 4: CD74HC4067 address pin S1
- 5: CD74HC4067 address pin S2
- 6: CD74HC4067 address pin S3
Optionally you can connect the enable pin as well, this is useful if you want to use multiple multiplexers with the same address lines and the same analog input. Otherwise, just connect the enable pin to ground.
If you are using a 3-bit multiplexer, like the CD74HC4051, you can uncomment the code specific to this multiplexer, and use only three address pins.
Behavior
Connect some potentiometers or other analog sensors to the 16 inputs of the multiplexer, and open the serial monitor (CTRL+SHIFT+M) or the serial plotter (CTRL+SHIFT+L). You should see all 16 signals printed or plotted.
Written by Pieter P, 31-01-2019
https://github.com/tttapa/Arduino-Helpers
A0,
{3, 4, 5, 6},
};
void setup() {
mux.begin();
}
void loop() {
for (
pin_t pin = 0; pin < mux.getLength(); ++pin) {
Serial.print(mux.analogRead(pin));
Serial.print('\t');
}
Serial.println();
}
void loop2() {
for (
pin_t pin : mux.pins()) {
Serial.print('\t');
}
Serial.println();
}
Dummy header file for Arduino builder.
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
A class for reading multiplexed analog inputs.
void begin() override
Initialize the multiplexer: set the pin mode of the address pins and the enable pin to output mode.
analog_t analogRead(pin_t pin)
An ExtIO version of the Arduino function.