// Pin Definitions
const uint8_t muxControlPins[] = {2, 3, 4 ,5}; // Control pins for the MUX (A0, A1, A2)
const uint8_t muxSignalPin = A0; // Signal output from MUX connected to A0
// Number of MUX, Encoders, Potentiometers, and Buttons
const uint8_t numEncodersPerMux = 4; // Encoders per MUX
const uint8_t numPotsD = 3; // Pots on MUX D
const uint8_t numPotsE = 3; // Pots on MUX E
const uint8_t numButtonsC = 2; // Buttons on MUX C
// Encoder Input Mapping for MUX C
const int encoderInputsC[numEncodersPerMux][3] = {
{0, 1, 2}, // Encoder 1: C0 (CLK), C1 (DT), C2 (SW)
{3, 4, 5}, // Encoder 2: C3 (CLK), C4 (DT), C5 (SW)
{6, 7, 8}, // Encoder 3: C6 (CLK), C7 (DT), C8 (SW)
{9, 10, 11} // Encoder 4: C9 (CLK), C10 (DT), C11 (SW)
};
// Encoder Input Mapping for MUX D
const int encoderInputsD[numEncodersPerMux][3] = {
{0, 1, 2}, // Encoder 1: D0 (CLK), D1 (DT), D2 (SW)
{3, 4, 5}, // Encoder 2: D3 (CLK), D4 (DT), D5 (SW)
{6, 7, 8}, // Encoder 3: D6 (CLK), D7 (DT), D8 (SW)
{9, 10, 11} // Encoder 4: D9 (CLK), D10 (DT), D11 (SW)
};
// Encoder Input Mapping for MUX E
const int encoderInputsE[numEncodersPerMux][3] = {
{0, 1, 2}, // Encoder 1: E0 (CLK), E1 (DT), E2 (SW)
{3, 4, 5}, // Encoder 2: E3 (CLK), E4 (DT), E5 (SW)
{6, 7, 8}, // Encoder 3: E6 (CLK), E7 (DT), E8 (SW)
{9, 10, 11} // Encoder 4: E9 (CLK), E10 (DT), E11 (SW)
};
// Potentiometer Input Mapping for MUX D
const int potInputsD[numPotsD] = {
12, // Potentiometer 1: D12
13, // Potentiometer 2: D13
14 // Potentiometer 3: D14
};
// Potentiometer Input Mapping for MUX E
const int potInputsE[numPotsE] = {
12, // Potentiometer 1: E12
13, // Potentiometer 2: E13
14 // Potentiometer 3: E14
};
// Button Input Mapping for MUX C
const int buttonInputsC[numButtonsC] = {
12, // Button 1: C12
13 // Button 2: C13
};
// Setup function to initialize MUX control pins
void setup() {
for (uint8_t i = 0; i < sizeof(muxControlPins); i++) {
pinMode(muxControlPins[i], OUTPUT); // Set control pins as OUTPUT
}
// Set the signal pin to INPUT
pinMode(muxSignalPin, INPUT);
Serial.begin(9600); // Initialize Serial communication
}
// Function to read inputs from the MUX and print values
void readInputs() {
Serial.println("Reading inputs...");
// Example reading logic
for (uint8_t muxIndex = 0; muxIndex < 3; muxIndex++) {
// Select the MUX
for (uint8_t i = 0; i < 3; i++) {
digitalWrite(muxControlPins[i], (muxIndex >> i) & 0x01); // Control MUX selection
}
// Read encoders for the selected MUX
for (uint8_t encoderIndex = 0; encoderIndex < numEncodersPerMux; encoderIndex++) {
int clkValue = digitalRead(encoderInputsC[encoderIndex][0]); // Change to encoderInputsD or encoderInputsE as needed
int dtValue = digitalRead(encoderInputsC[encoderIndex][1]); // Change to encoderInputsD or encoderInputsE as needed
Serial.print("Encoder "); Serial.print(encoderIndex + 1);
Serial.print(": CLK = "); Serial.print(clkValue);
Serial.print(", DT = "); Serial.println(dtValue);
}
// Read potentiometers
for (uint8_t potIndex = 0; potIndex < numPotsD; potIndex++) { // Change to potInputsE as needed
int potValue = analogRead(potInputsD[potIndex]);
Serial.print("Potentiometer "); Serial.print(potIndex + 1);
Serial.print(": Value = "); Serial.println(potValue);
}
// Read buttons
for (uint8_t buttonIndex = 0; buttonIndex < numButtonsC; buttonIndex++) {
int buttonState = digitalRead(buttonInputsC[buttonIndex]);
Serial.print("Button "); Serial.print(buttonIndex + 1);
Serial.print(": State = "); Serial.println(buttonState);
}
}
}
void loop() {
readInputs(); // Call the function to read inputs
delay(1000); // Delay for 1 second before the next read
}