programming
float RGB[3];
int ldrPin = 4;
int ambientLight;
int redLed = 9;
int greenLed = 5;
int blueLed = 7;
void setup(){
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(blueLed,OUTPUT);
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);
if(ambientLight<600){
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);
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.