41 AnalogMultiplex(pin_t analogPin, const Array<pin_t, N> &addressPins,
42 pin_t enablePin = NO_PIN)
43 : analogPin(analogPin), addressPins(addressPins), enablePin(enablePin) {
61 void pinMode(pin_int_t pin, PinMode_t mode) override;
66 void pinModeBuffered(pin_int_t pin, PinMode_t mode) override;
72 void digitalWrite(pin_int_t, PinStatus_t) override
73 __attribute__((deprecated)) {}
78 void digitalWriteBuffered(pin_int_t, PinStatus_t) override
79 __attribute__((deprecated)) {}
87 PinStatus_t digitalRead(pin_int_t pin) override;
92 PinStatus_t digitalReadBuffered(pin_int_t pin) override;
100 analog_t analogRead(pin_int_t pin) override;
105 analog_t analogReadBuffered(pin_int_t pin) override;
111 void analogWrite(pin_int_t, analog_t) override
112 __attribute__((deprecated)) {}
117 void analogWriteBuffered(pin_int_t, analog_t) override
118 __attribute__((deprecated)) {}
124 void begin() override;
130 void updateBufferedOutputs() override {}
136 void updateBufferedInputs() override {}
142 void discardFirstReading(bool discardFirstReading_) {
143 this->discardFirstReading_ = discardFirstReading_;
147 const pin_t analogPin;
148 const Array<pin_t, N> addressPins;
149 const pin_t enablePin;
150 bool discardFirstReading_ = true;
159 void setMuxAddress(uint8_t address);
167 void prepareReading(uint8_t address);
175 constexpr static auto MUX_ENABLED = LOW;
176 constexpr static auto MUX_DISABLED = HIGH;
221analog_t AnalogMultiplex<N>::analogRead(pin_int_t pin) {
222 prepareReading(static_cast<uint8_t>(pin));
223 if (discardFirstReading_)
224 (void)ExtIO::analogRead(analogPin);
225 analog_t result = ExtIO::analogRead(analogPin);
236void AnalogMultiplex<N>::begin() {
237 for (const pin_t &addressPin : addressPins)
238 ExtIO::pinMode(addressPin, OUTPUT);
239 if (enablePin != NO_PIN) {
240 ExtIO::pinMode(enablePin, OUTPUT);
241 ExtIO::digitalWrite(enablePin, MUX_DISABLED);
246void AnalogMultiplex<N>::setMuxAddress(uint8_t address) {
248 for (const pin_t &addressPin : addressPins) {
249 ExtIO::digitalWrite(addressPin, (address & mask) != 0 ? HIGH : LOW);
252#if !defined(__AVR__) && defined(ARDUINO)
253 delayMicroseconds(SELECT_LINE_DELAY);