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 = 2; // Number of multiplexers
const int LED_PIN_1 = 4; // First LED pin
const int LED_PIN_2 = 5; // Second LED pin
void setup() {
pinMode(MUX_S0, OUTPUT);
pinMode(MUX_S1, OUTPUT);
pinMode(MUX_S2, OUTPUT);
pinMode(MUX_S3, OUTPUT);
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (int mux = 0; mux < NUM_MULTIPLEXERS; mux++) {
for (int channel = 0; channel < NUM_MUX_CHANNELS; channel++) {
// Set the multiplexer control pins
setMuxControlPins(mux, channel);
// Turn on the LEDs
digitalWrite(LED_PIN_1, HIGH);
digitalWrite(LED_PIN_2, HIGH);
// Wait for a second
delay(1000);
// Turn off the LEDs
digitalWrite(LED_PIN_1, LOW);
digitalWrite(LED_PIN_2, LOW);
// Delay before the next channel
delay(100); // Delay for better readability, adjust as needed
}
}
}
void setMuxControlPins(int mux, 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));
}