const int potPin = 34; // Pin connected to the potentiometer
const int ledPin1 = 2; // Pin connected to the first LED
const int ledPin2 = 4; // Pin connected to the second LED
void setup() {
pinMode(ledPin1, OUTPUT); // Set LED1 as output
pinMode(ledPin2, OUTPUT); // Set LED2 as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int potValue = analogRead(potPin); // Read potentiometer value (0-1023)
int ledBrightness = map(potValue, 0, 4095, 0, 255); // Map potentiometer to LED brightness (0-255)
analogWrite(ledPin1, ledBrightness); // Adjust brightness of LED1
analogWrite(ledPin2, 255 - ledBrightness); // Adjust brightness of LED2 in opposite direction
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" | LED1 Brightness: ");
Serial.print(ledBrightness);
Serial.print(" | LED2 Brightness: ");
Serial.println(255 - ledBrightness);
delay(10); // Small delay to make the readings stable
}