Hwello, I hope everyone is having a wonderful holiday. I am trying to create a clock using four 7-segment displays connected to two 16-channel Arduino multiplexers. I have used one multiplexer to control the top and another to control the bottom of the displays. When I run the code separately through each multiplexer, all their respective LEDs light up, but when I try to run both multiplexers simultaneously, it does not work. I think it either has something to do with the multiplexers conflicting or the code. Because when I connect to a jumper cable from the power and touch the pins on the multiplexers, the LEDs work. The codes are:
multiplexer 1-
// Define multiplexer control pins
const int S0 = 8;
const int S1 = 9;
const int S2 = 10;
const int S3 = 11;
const int SIG = 12; // Signal pin to control LEDs
// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"
void setup() {
// Set multiplexer control pins as outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Set SIG pin as output
pinMode(SIG, OUTPUT);
}
void loop() {
// Continuously display the binary code on all channels
for (int channel = 0; channel < 15; channel++) { // Loop through all 16 channels
selectMultiplexerChannel(channel); // Select the appropriate channel
digitalWrite(SIG, bitRead(binaryCode, channel % 8)); // Send the appropriate binary signal
}
}
// Function to select a channel on the multiplexer
void selectMultiplexerChannel(int channel) {
digitalWrite(S0, bitRead(channel, 0)); // Set S0 based on bit 0 of the channel
digitalWrite(S1, bitRead(channel, 1)); // Set S1 based on bit 1 of the channel
digitalWrite(S2, bitRead(channel, 2)); // Set S2 based on bit 2 of the channel
digitalWrite(S3, bitRead(channel, 3)); // Set S3 based on bit 3 of the channel
}
multiplexer 2-
// Define multiplexer control pins
const int S0 = 7;
const int S1 = 6;
const int S2 = 5;
const int S3 = 4;
const int SIG = 3; // Signal pin to control LEDs
// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"
void setup() {
// Set multiplexer control pins as outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Set SIG pin as output
pinMode(SIG, OUTPUT);
}
void loop() {
// Continuously display the binary code on all channels
for (int channel = 0; channel < 15; channel++) { // Loop through all 16 channels
selectMultiplexerChannel(channel); // Select the appropriate channel
digitalWrite(SIG, bitRead(binaryCode, channel % 8)); // Send the appropriate binary signal
}
}
// Function to select a channel on the multiplexer
void selectMultiplexerChannel(int channel) {
digitalWrite(S0, bitRead(channel, 0)); // Set S0 based on bit 0 of the channel
digitalWrite(S1, bitRead(channel, 1)); // Set S1 based on bit 1 of the channel
digitalWrite(S2, bitRead(channel, 2)); // Set S2 based on bit 2 of the channel
digitalWrite(S3, bitRead(channel, 3)); // Set S3 based on bit 3 of the channel
}
Multiplexer 1 + 2-
// Define multiplexer 1 control pins
const int S0_1 = 7;
const int S1_1 = 6;
const int S2_1 = 5;
const int S3_1 = 4;
const int SIG_1 = 3; // Signal pin to control LEDs for multiplexer 1
// Define multiplexer 2 control pins
const int S0_2 = 8;
const int S1_2 = 9;
const int S2_2 = 10;
const int S3_2 = 11;
const int SIG_2 = 12; // Signal pin to control LEDs for multiplexer 2
// Variable to hold the binary code for the number to display
byte binaryCode = 0b11111111; // Example: binary code for "0"
// Define which channels to activate (can be 0-7 for multiplexer 1, 0-7 for multiplexer 2)
int channel1 = 0; // Example: Channel 0 for multiplexer 1
int channel2 = 8; // Example: Channel 8 for multiplexer 2
void setup() {
// Set multiplexer 1 control pins as outputs
pinMode(S0_1, OUTPUT);
pinMode(S1_1, OUTPUT);
pinMode(S2_1, OUTPUT);
pinMode(S3_1, OUTPUT);
pinMode(SIG_1, OUTPUT);
// Set multiplexer 2 control pins as outputs
pinMode(S0_2, OUTPUT);
pinMode(S1_2, OUTPUT);
pinMode(S2_2, OUTPUT);
pinMode(S3_2, OUTPUT);
pinMode(SIG_2, OUTPUT);
}
void loop() {
// Manually turn on channel 0 of multiplexer 1
selectMultiplexerChannel(channel1, 1);
digitalWrite(SIG_1, bitRead(binaryCode, channel1)); // Send the appropriate binary signal for channel1
delay(10); // Wait for 1 second
// Manually turn off channel 0 of multiplexer 1 (optional, if you want to turn it off before switching)
digitalWrite(SIG_1, LOW);
delay(50); // Wait for 500 ms
// Manually turn on channel 8 of multiplexer 2
selectMultiplexerChannel(channel2 - 8, 2); // Adjust channel number for multiplexer 2 (0-7)
digitalWrite(SIG_2, bitRead(binaryCode, channel2)); // Send the appropriate binary signal for channel2
delay(10); // Wait for 1 second
// Manually turn off channel 8 of multiplexer 2 (optional)
digitalWrite(SIG_2, LOW);
delay(500); // Wait for 500 ms
}
// Function to select a channel on the specified multiplexer
void selectMultiplexerChannel(int channel, int multiplexer) {
if (multiplexer == 1) {
// Set control pins for multiplexer 1
digitalWrite(S0_1, bitRead(channel, 0));
digitalWrite(S1_1, bitRead(channel, 1));
digitalWrite(S2_1, bitRead(channel, 2));
digitalWrite(S3_1, bitRead(channel, 3));
} else if (multiplexer == 2) {
// Set control pins for multiplexer 2
digitalWrite(S0_2, bitRead(channel, 0));
digitalWrite(S1_2, bitRead(channel, 1));
digitalWrite(S2_2, bitRead(channel, 2));
digitalWrite(S3_2, bitRead(channel, 3));
}
}
Any help is much apprepricated thx
