#define LED_PIN 13
#define SW_PIN 15
#define POT_PIN 25
int SwitchState=0;
int potValue=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(SW_PIN, INPUT);
pinMode(POT_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("min:-50, max:4150,");
SwitchState = digitalRead(SW_PIN); // read the state of the switch
Serial.print ("SwitchState:");
Serial.print(4095 * SwitchState); // send the state to serial monitor
potValue = analogRead(POT_PIN); // read the value of the pottentiometer
Serial.print (",potValue:");
Serial.println(potValue); // send the value to serial monitor
int ledBrightness = map(potValue, 0, 4095, 0, 255); // map potValue to PWM range
if (SwitchState)
analogWrite (LED_PIN,ledBrightness); // set LED brightness based on potValue if the switch slides left)
else
analogWrite (LED_PIN,0); // turn the LED oƯ if the switch slides right
delay (100); // wait 100 ms
}