const int MUX_S0 = 0; // Multiplexer control pin S0
const int MUX_S1 = 1; // Multiplexer control pin S1
const int MUX_S2 = 2; // Multiplexer control pin S2
const int MUX_S3 = 3; // Multiplexer control pin S3
const int NUM_MUX_CHANNELS = 16; // Number of channels per multiplexer
const int NUM_MULTIPLEXERS = 1; // Number of multiplexers (changed to 1)
const int LED_PIN = 4; // LED pin (connect to one of the output pins of the multiplexer)
void setup() {
pinMode(MUX_S0, OUTPUT);
pinMode(MUX_S1, OUTPUT);
pinMode(MUX_S2, OUTPUT);
pinMode(MUX_S3, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (int channel = 0; channel < NUM_MUX_CHANNELS; channel++) {
// Set the multiplexer control pins
setMuxControlPins(channel);
// Turn on the LED
digitalWrite(LED_PIN, HIGH);
// Wait for a second
delay(1000);
// Turn off the LED
digitalWrite(LED_PIN, LOW);
// Delay before the next channel
delay(100); // Delay for better readability, adjust as needed
}
}
void setMuxControlPins(int channel) {
digitalWrite(MUX_S0, bitRead(channel, 0));
digitalWrite(MUX_S1, bitRead(channel, 1));
digitalWrite(MUX_S2, bitRead(channel, 2));
digitalWrite(MUX_S3, bitRead(channel, 3));
}