int ldr = 25; // Pin del LDR
int pot = 32; // Pin del potenciómetro
int led1 = 23; // Pin del LED 1
int led2 = 18; // Pin del LED 2
int ledChannel = 0; //va de 0 a 15
int resolution(8); //la salida va de 0 a 255 con esta resolucion
int freq = 5000;
int pwm;
void setup() {
Serial.begin(115200);
pinMode(led2, OUTPUT);
pinMode(pot, INPUT);
pinMode(ldr, INPUT);
ledcSetup(ledChannel,freq,resolution);
ledcAttachPin(led1,ledChannel);
analogReadResolution(10); //para llegar a 1023 (max. de Arduino)
}
void loop() {
int ldrValor = analogRead(ldr);
int potValor = analogRead(pot);
int brillo1 = map(potValor, 0, 1023, 0, 255);
int brillo2 = map(ldrValor, 0, 1023, 0, 255);
//analogWrite(led1, brillo1);
analogWrite(led2, brillo2);
ledcWrite(ledChannel,brillo1);
delay(10);
}