Diagrama protoboard
Diagrama esquemático
Foto montaje
Código Arduino
loat
RGB[3];
int ldrPin = 0;
int ambientLight;
int redLed = 11;
int greenLed = 10;
int blueLed = 9;
void setup(){
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(blueLed,OUTPUT);
// set all the outputs to low
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
void loop(){
for (float x=0;x<PI;x=x+0.00001){
RGB[0]=255*abs(sin(x*(180/PI)));
RGB[1]=255*abs(sin((x+PI/3)*(180/PI)));
RGB[2]=255*abs(sin((x+(2*PI)/3)*(180/PI)));
ambientLight=analogRead(ldrPin);
analogWrite(redLed,RGB[0]);
analogWrite(greenLed,RGB[1]);
analogWrite(blueLed,RGB[2]);
}
else{
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
digitalWrite(blueLed,LOW);
}
for(int i=0;i<3;i++){
if(RGB[i]<1){
delay(100);
}
if(RGB[i]<5){
delay(50);
}
if(RGB[i]<10){
delay(10);
}
if(RGB[i]<100){
delay(5);
}
}
delay(1);
}
}
Vídeo
// por ausencia de oscuridad en el laboratorio los led no se apagaban del todo
No hay comentarios:
Publicar un comentario