const int ledPin = 10;
const int ledPin2 = 11;
const int buzzerPin = 9;
const int potPin = A0;
void setup() {
pinMode(ledPin, OUTPUT); // Initialize ledPin as output
pinMode(ledPin2, OUTPUT); // Initialize ledPin2 as output
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600); // Start serial communication
}
void loop() {
int potValue = analogRead(potPin); // Read the potentiometer value
// Map potentiometer value (0-1023) to LED brightness (0-255)
int ledBrightness = map(potValue, 0, 1023, 0, 255);
int buzzerFrequency = map(potValue, 0, 1023, 0, 1000);
// Control the brightness of both LEDs
analogWrite(ledPin, ledBrightness); // First LED: brightness from potentiometer
analogWrite(ledPin2, 255 - ledBrightness); // Second LED: inverse brightness
// Print the potentiometer value and LED brightness to the Serial Monitor
tone(buzzerPin, buzzerFrequency);
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" LED1 Brightness: ");
Serial.print(ledBrightness);
Serial.print(" LED2 Brightness: ");
Serial.println(255 - ledBrightness);
Serial.print(" | Buzzer Frequency: ");
Serial.println(buzzerFrequency);
delay(1000); // Shorter delay for smoother updates (optional)
}