//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));
//}
const int MUX_S0 = 0; // Multiplexer 1 control pin S0
const int MUX_S1 = 1; // Multiplexer 1 control pin S1
const int MUX_S2 = 2; // Multiplexer 1 control pin S2
const int MUX_S3 = 3; // Multiplexer 1 control pin S3
const int MUX_S0_2 = 5; // Multiplexer 2 control pin S0
const int MUX_S1_2 = 6; // Multiplexer 2 control pin S1
const int MUX_S2_2 = 7; // Multiplexer 2 control pin S2
const int MUX_S3_2 = 8; // Multiplexer 2 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 = 8; // First LED pin
const int LED_PIN_2 = 9; // Second LED pin
void setup() {
pinMode(MUX_S0, OUTPUT);
pinMode(MUX_S1, OUTPUT);
pinMode(MUX_S2, OUTPUT);
pinMode(MUX_S3, OUTPUT);
pinMode(MUX_S0_2, OUTPUT);
pinMode(MUX_S1_2, OUTPUT);
pinMode(MUX_S2_2, OUTPUT);
pinMode(MUX_S3_2, 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
if (mux == 0) {
setMuxControlPins(mux, channel);
} else if (mux == 1) {
setMuxControlPins_2(mux, channel);
}
// Turn on the LEDs
digitalWrite(LED_PIN_1, HIGH);
digitalWrite(LED_PIN_2, HIGH);
// Wait for a second
delay(100);
// 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));
}
void setMuxControlPins_2(int mux, int channel) {
digitalWrite(MUX_S0_2, bitRead(channel, 5));
digitalWrite(MUX_S1_2, bitRead(channel, 6));
digitalWrite(MUX_S2_2, bitRead(channel, 7));
digitalWrite(MUX_S3_2, bitRead(channel, 8));
}