const int potentiometerPin = A0; // potentiometer is connected to analog pin A0
const int ledPin_Right = 3; // LED is connected to digital pin 3
const int ledPin_Left = 4;
void setup() {
Serial.begin(9600);
pinMode(ledPin_Right, OUTPUT); // set the LED pin as an output
pinMode(ledPin_Left, OUTPUT);
}
void loop() {
// read the value of the potentiometer
int potentiometerValue = analogRead(potentiometerPin);
// map the potentiometer value to a range suitable for the LED
int ledBrightness = map(potentiometerValue, 0, 1023, 0, 255);
if (ledBrightness > 174) {
digitalWrite(ledPin_Right, HIGH); // turn off the LED if the sensor value is less than 512
}
else {
digitalWrite(ledPin_Right, LOW);
}
if (ledBrightness < 78) {
digitalWrite(ledPin_Left, HIGH); // turn on the LED if the sensor value is greater than or equal to 512
}
else {
digitalWrite(ledPin_Left, LOW);
}
Serial.println(ledBrightness);
// set the brightness of the LED
// analogWrite(ledPin_Right, ledBrightness);
// delay(400);
}