First I declare my two pins. Then I set led as an OUTPUT while is not necessary to declare analog inputs because ArduinoIDE detects them as that
The last step is to code the main logic in the void loop which it consists in two lines. The first one is dedicated to obtain the analog to digital conversion from the potenciometer and make a scale change because the ADC scale is within values of 0 to 1023 but the PWM range goes from 0 to 255. In order to achieve that scale change, I use the map function and storage the new value in a variable named "valor"
The last code line is to write the variable "valor" in the analogWrite function. In this way the pwm value depends on the ADC conversion from the potenciometer.
/*Paste your code here*/
const char led = 6;
const char pot = A0;
void setup() { pinMode(led, OUTPUT);}
void loop() {
int valor = map(analogRead(pot), 0, 1023, 0, 255);
analogWrite(led, valor);
} Add video of output (know more)
Add a photo of your hardware showing the output.
