int led1 = 15;
int led2 = 2;
int led3 = 4;
int led4 = 5;
int poten = 13;
int ldr = 12;
int luz;
const int freq = 5000;
const int ledChannel = 0;
const int ledChannel2 = 1;
const int ledChannel3 = 2;
const int ledChannel4 = 3;
const int resolution = 8;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("El potenciómetro determina la velocidad de parpadeo, el LDR determina la cantidad de luces encendidas y su intensidad :)");
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(poten, INPUT);
pinMode(ldr, INPUT);
analogReadResolution(10);
ledcSetup(ledChannel, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
ledcSetup(ledChannel3, freq, resolution);
ledcSetup(ledChannel4, freq, resolution);
ledcAttachPin(led1, ledChannel);
ledcAttachPin(led2, ledChannel2);
ledcAttachPin(led3, ledChannel3);
ledcAttachPin(led4, ledChannel4);
}
void loop() {
// put your main code here, to run repeatedly:
delay(map(analogRead(poten),0,1023,300,1500));
ledcWrite(ledChannel,0);
ledcWrite(ledChannel2,0);
ledcWrite(ledChannel3,0);
ledcWrite(ledChannel4,0);
delay(map(analogRead(poten),0,1023,300,1500));
Serial.print("Delay de parpadeo (ms): ");
Serial.println(map(analogRead(poten),0,1023,300,1500));
delay(10); // this speeds up the simulation
luz=analogRead(ldr);
if(luz>762){
ledcWrite(ledChannel, map(analogRead(ldr),8,1015,0,255));
ledcWrite(ledChannel2, 0);
ledcWrite(ledChannel3, 0);
ledcWrite(ledChannel4, 0);
Serial.println("Luz 1 prendida.");
}else if(luz>508){
ledcWrite(ledChannel, 255);
ledcWrite(ledChannel2, map(analogRead(ldr),8,1015,0,255));
ledcWrite(ledChannel3, 0);
ledcWrite(ledChannel4, 0);
Serial.println("Luces 1 y 2");
}else if(luz>254){
ledcWrite(ledChannel, 255);
ledcWrite(ledChannel2, 255);
ledcWrite(ledChannel3, map(analogRead(ldr),8,1015,0,255));
ledcWrite(ledChannel4, 0);
Serial.println("Luces 1, 2 y 3");
}else{
ledcWrite(ledChannel, 255);
ledcWrite(ledChannel2, 255);
ledcWrite(ledChannel3, 255);
ledcWrite(ledChannel4, map(analogRead(ldr),8,1015,0,255));
Serial.println("Todas las luces");
}
//ledcWrite(ledChannel, map(analogRead(ldr),8,254,0,255));
// ledcWrite(ledChannel2, map(analogRead(ldr),8,508,0,255));
// ledcWrite(ledChannel3, map(analogRead(ldr),8,762,0,255));
// ledcWrite(ledChannel4, map(analogRead(ldr),8,1015,0,255));
}