# CD74HC4067
# 16-Channel Analog Multiplexer
# https://www.ti.com/lit/ds/symlink/cd74hc4067.pdf

from machine import Pin, ADC
import time

s0 = Pin(22, Pin.OUT)
s1 = Pin(21, Pin.OUT)
s2 = Pin(19, Pin.OUT)
s3 = Pin(18, Pin.OUT)

s_pins = [s0, s1, s2, s3]

adc = ADC(32)

def read_mux(channel):
    for i in range(4):
        s_pins[i].value(channel >> i & 1)
    time.sleep(0.05)
    return adc.read()     

while True:   
    for i in range(6):
        print(read_mux(i), end=",")
    print(read_mux(6))
    time.sleep(1)
Loading
cd74hc4067