const int POT = A0;
const int LED1 = 9;
int sensorValue = 0;
int outputValue = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED1, OUTPUT);
pinMode(POT, INPUT);
}
void loop() {
// read pot value
sensorValue = analogRead(POT);
// map pot value to the brightness of the light
outputValue = map(sensorValue, 0, 1023, 0, 255);
// display results on serial monitor
Serial.print("potvalue = ");
Serial.print(sensorValue);
Serial.print("\t ledbrightness = ");
Serial.println(outputValue);
// identify whether the value of output is 800 on pot
if (sensorValue <= 800) {
analogWrite(LED1, outputValue);
} else {
(sensorValue >= 801);
analogWrite(LED1, LOW);
}
}