const int potentiometerPin = 34; // Pin connected to the potentiometer
const int ledPin = 2; // Pin connected to the LED
void setup() {
// Initialize Serial communication
Serial.begin(115200);
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the analog input from the potentiometer
int potValue = analogRead(potentiometerPin);
// Map the potentiometer values to LED intensity levels
int ledIntensity = map(potValue, 0, 4095, 0, 255);
// Control the LED intensity using analogWrite
analogWrite(ledPin, ledIntensity);
// Print potentiometer values and LED intensity to Serial Monitor
Serial.print("Potentiometer: ");
Serial.print(potValue);
Serial.print(" | LED Intensity: ");
Serial.println(ledIntensity);
// Add your custom logic for different LED behaviors based on potentiometer ranges
if (potValue < 1024) {
// Add behavior for low potentiometer range
// For example, turn on a second LED
digitalWrite(4, HIGH); // Assuming pin 4 is connected to another LED
} else if (potValue < 2048) {
// Add behavior for medium potentiometer range
// For example, blink the LED
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
} else {
// Add behavior for high potentiometer range
// For example, turn off the second LED
digitalWrite(4, LOW); // Assuming pin 4 is connected to another LED
}
delay(100); // Add a small delay to avoid flickering in the Serial Monitor
}