const int numPotentiometers = 6;
const int potentiometerPins[numPotentiometers] = {A0, A1, A2, A3, A4, A5};
const int ledPins[numPotentiometers] = {7,8, 9,10 , 11,6};
int potentiometerValues[numPotentiometers];
void setup() {
// Initialize serial communication for debugging (optional)
Serial.begin(9600);
// Set the LED pins as OUTPUT
for (int i = 0; i < numPotentiometers; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read analog values from potentiometers
for (int i = 0; i < numPotentiometers; i++) {
potentiometerValues[i] = analogRead(potentiometerPins[i]);
}
// Find the two greatest values
int greatestValue = 0;
int secondGreatestValue = 0;
int greatestIndex = -1;
int secondGreatestIndex = -1;
for (int i = 0; i < numPotentiometers; i++) {
if (potentiometerValues[i] > greatestValue) {
secondGreatestValue = greatestValue;
secondGreatestIndex = greatestIndex;
greatestValue = potentiometerValues[i];
greatestIndex = i;
} else if (potentiometerValues[i] > secondGreatestValue) {
secondGreatestValue = potentiometerValues[i];
secondGreatestIndex = i;
}
}
// Control the LEDs based on the two greatest potentiometers
for (int i = 0; i < numPotentiometers; i++) {
if (i == greatestIndex || i == secondGreatestIndex) {
digitalWrite(ledPins[i], HIGH); // Turn on LED
} else {
digitalWrite(ledPins[i], LOW); // Turn off LED
}
}
// For debugging: Print potentiometer values and the two greater values
Serial.print("Potentiometer values: ");
for (int i = 0; i < numPotentiometers; i++) {
Serial.print(potentiometerValues[i]);
Serial.print(" ");
}
Serial.println();
Serial.print("Two greatest values: ");
Serial.print(greatestValue);
Serial.print(" ");
Serial.println(secondGreatestValue);
Serial.println("------");
delay(50); // Adjust the delay as needed
}