int blau=3;
int rot=5;
int gruen=9;
void setup(){
pinMode(rot,OUTPUT);
pinMode(gruen,OUTPUT);
pinMode(blau,OUTPUT);
analogWrite(rot,255);
analogWrite(gruen,0);
analogWrite(blau,0);
}
void loop(){
analogWrite(rot,0);
analogWrite(gruen,255);
analogWrite(blau,0);
delay(500);
analogWrite(rot,0);
analogWrite(gruen,0);
analogWrite(blau,255);
delay(500);
analogWrite(rot,255);
analogWrite(gruen,255);
analogWrite(blau,255);
delay(500);
analogWrite(rot,255);
analogWrite(gruen,0);
analogWrite(blau,0);
delay(500);
analogWrite(rot,50);
analogWrite(gruen,0);
analogWrite(blau,0);
delay(500);
}
Um den Code einfacher zu gestalten, definieren wir eine neue Methode farbe, mit der die LED in einer bestimmten Farbe leuchten soll.
void farbe(int r,int g,int b){
analogWrite(rot,r);
analogWrite(gruen,g);
analogWrite(blau,b);
}