Arduino Kontrollü Renk Değiştiren LED Lamba
int red = 9;
int green = 10;
int blue = 11;
int mytime = 20;
void setup(){
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
switchOff();
}
void loop(){
rainbowFade();
}
void switchOn(int r,int g,int b){
r = 255 - r;
g = 255 - g;
b = 255 - b;
analogWrite(red, r);
analogWrite(green, g);
analogWrite(blue, b);
delay(mytime);
}
void switchOff(){
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 255);
}
void rainbowFade(){
for(int i=255; i>=0; i--){
int j = 255 - i;
switchOn(i,j,0);
}
for(int i=255; i>=0; i--){
int j = 255 - i;
switchOn(0,i,j);
}
for(int i=255; i>=0; i--){
int j = 255 - i;
switchOn(j,0,i);
}
}
0 yorum: