#include <Arduino.h>
#include <Wire.h>
// Define the CD74HC4067 pins
const int s0Pin = 2;
const int s1Pin = 3;
const int s2Pin = 4;
const int s3Pin = 5;
const int analogInPin = 0; // Connect this to the common pin (Y0) of CD74HC4067
const int ldrMapMin = 0; // Minimum mapping value for LDRs
const int ldrMapMax = 1023; // Maximum mapping value for LDRs
const unsigned long interval = 500; // Delay between readings (1 second)
unsigned long previousMillis = 0;
void setup() {
// Initialize the CD74HC4067 pins
pinMode(s0Pin, OUTPUT);
pinMode(s1Pin, OUTPUT);
pinMode(s2Pin, OUTPUT);
pinMode(s3Pin, OUTPUT);
// Start the serial communication for displaying values
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
for (int channel = 0; channel < 16; channel++) {
// Set the MUX to the current channel
selectMuxChannel(channel);
// Read the analog value from the selected channel
int sensorValue = analogRead(analogInPin);
// Map the values for channels 4-7 to channels 0-3
int mappedValue;
if (channel >= 4 && channel <= 7) {
// Use the potentiometer values to map the LDR readings
int potValue = analogRead(channel - 4); // Read the corresponding potentiometer value
mappedValue = map(sensorValue, 0, 1023, ldrMapMin, potValue);
} else {
mappedValue = sensorValue;
}
// Differentiate between LDRs and potentiometers
if (channel >= 0 && channel <= 3) {
Serial.print("LDR");
} else if (channel >= 4 && channel <= 7) {
Serial.print("Potentio");
} else {
continue; // Ignore other channels
}
Serial.print(channel % 4); // Display channel number (0-3) for LDRs and (0-3) for Potentiometers
Serial.print(" : ");
Serial.print(mappedValue);
if (channel == 7) {
Serial.println(); // Print a new line after processing channels 0-3 and 4-7
} else {
Serial.print(" : ");
}
}
}
}
void selectMuxChannel(int channel) {
// Set the MUX channel by setting the appropriate S0-S3 pins
digitalWrite(s0Pin, channel & 0x01);
digitalWrite(s1Pin, (channel >> 1) & 0x01);
digitalWrite(s2Pin, (channel >> 2) & 0x01);
digitalWrite(s3Pin, (channel >> 3) & 0x01);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL
pot1:GND
pot1:SIG
pot1:VCC
pot2:GND
pot2:SIG
pot2:VCC
pot3:GND
pot3:SIG
pot3:VCC
pot4:GND
pot4:SIG
pot4:VCC
r1:1
r1:2
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
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO
ldr2:VCC
ldr2:GND
ldr2:DO
ldr2:AO
ldr3:VCC
ldr3:GND
ldr3:DO
ldr3:AO
ldr4:VCC
ldr4:GND
ldr4:DO
ldr4:AO
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
r2:1
r2:2
r3:1
r3:2