const int s0Pin = 49; // S0 pin
const int s1Pin = 51; // S1 pin
const int s2Pin = 53; // S2 pin
const int s3Pin = 52; // S3 pin
const int numSwitches = 16; // Total number of switches
const int numMuxChannels = 16; // Number of multiplexer channels
void setup() {
pinMode(s0Pin, OUTPUT);
pinMode(s1Pin, OUTPUT);
pinMode(s2Pin, OUTPUT);
pinMode(s3Pin, OUTPUT);
// Set all the pins to LOW initially
digitalWrite(s0Pin, LOW);
digitalWrite(s1Pin, LOW);
digitalWrite(s2Pin, LOW);
digitalWrite(s3Pin, LOW);
Serial.begin(9600);
}
void loop() {
for (int channel = 0; channel < numMuxChannels; ++channel) {
// Set the multiplexer inputs using binary representation
digitalWrite(s0Pin, (channel & 0x01) ? HIGH : LOW);
digitalWrite(s1Pin, (channel & 0x02) ? HIGH : LOW);
digitalWrite(s2Pin, (channel & 0x04) ? HIGH : LOW);
digitalWrite(s3Pin, (channel & 0x08) ? HIGH : LOW);
// Read the state of the switch on the current channel
int switchState = digitalRead(48); // Assuming the switches are connected to analog pin A0
int test1 = digitalRead(49);
int test2 = digitalRead(51);
int test3 = digitalRead(53);
int test4 = digitalRead(52);
// Print the channel number and switch state
Serial.print("Channel: ");
Serial.print(channel);
Serial.print(" Switch State: ");
Serial.println(switchState);
Serial.print(test1);
Serial.print(test2);
Serial.print(test3);
Serial.print(test4);
delay(500); // Delay for stability
}
}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
mux1:I15
mux1:I14
mux1:I13
mux1:I12
mux1:I11
mux1:I10
mux1:I9
mux1:I8
mux1:I7
mux1:I6
mux1:I5
mux1:I4
mux1:I3
mux1:I2
mux1:I1
mux1:I0
mux1:COM
mux1:S3
mux1:S2
mux1:S1
mux1:S0
mux1:EN
mux1:VCC
mux1:GND
sw1:1a
sw1:2a
sw1:3a
sw1:4a
sw1:5a
sw1:6a
sw1:7a
sw1:8a
sw1:8b
sw1:7b
sw1:6b
sw1:5b
sw1:4b
sw1:3b
sw1:2b
sw1:1b