// CD74HC4067
// 16-Channel Analog Multiplexer
// https://www.ti.com/lit/ds/symlink/cd74hc4067.pdf
#include <Adafruit_NeoPixel.h>
const char * compiledOn = "\"" __FILE__ "\" compiled the " __DATE__ " at " __TIME__;
#define COM 34
#define NEO_PIXEL_PIN 4
#define NB_CHANNELS 16
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NB_CHANNELS, NEO_PIXEL_PIN, NEO_GRB + NEO_KHZ800);
const uint8_t controlPins[] = { 23, 22, 21, 19 };
float readMux(int channel)
{
for (int i = 0; i < 4; i ++)
{
digitalWrite(controlPins[i], channel >> i & 1);
}
delay(1);
return analogRead(COM);
}
void setup()
{
Serial.begin(115200);
while (!Serial) {}
Serial.println(compiledOn);
for (int i = 0; i < 4; ++i)
{
pinMode(controlPins[i], OUTPUT);
}
pixels.begin();
Serial.println("System Ready");
}
void loop()
{
static uint16_t potVal[NB_CHANNELS];
// pixels.clear();
for (int channelIndex = 0; channelIndex < NB_CHANNELS; ++channelIndex)
{
uint16_t potRead = readMux(channelIndex);
if ( potVal[channelIndex] != potRead) {
potVal[channelIndex] = potRead;
Serial.print("Pot ");
Serial.print(channelIndex + 1);
Serial.print(" = ");
Serial.println(potRead);
if (potRead > 1500)
{
pixels.setPixelColor(channelIndex, pixels.Color(0, 150, 0));
}
else
{
pixels.setPixelColor(channelIndex, pixels.Color(0, 0, 0));
}
}
}
pixels.show();
}Loading
cd74hc4067
cd74hc4067