|
我先发帖子上程序,随后让我慢慢补图和视频还有电路
int b = 11;
int r = 3;
int g = 5;
void setup()
{
pinMode(r, OUTPUT);
pinMode(g, OUTPUT);
pinMode(b, OUTPUT);
}
void bl()
{
digitalWrite(b,HIGH);
delay(100);
digitalWrite(b,LOW);
delay(100);
}
void re()
{
digitalWrite(r,HIGH);
delay(100);
digitalWrite(r,LOW);
delay(100);
}
void gr()
{
digitalWrite(g,HIGH);
delay(100);
digitalWrite(g,LOW);
delay(100);
}
void rg()
{
digitalWrite(g,HIGH);
digitalWrite(r,HIGH);
delay(100);
digitalWrite(g,LOW);
digitalWrite(r,LOW);
delay(100);
}
void rb()
{
digitalWrite(b,HIGH);
digitalWrite(r,HIGH);
delay(100);
digitalWrite(b,LOW);
digitalWrite(r,LOW);
delay(100);
}
void gb()
{
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
delay(100);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
delay(100);
}
void wite()
{
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(r,HIGH);
delay(100);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(r,HIGH);
delay(100);
}
void rp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(r, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(r, a);
delay(10);
}
}
void rgp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(r, a);
analogWrite(g, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(r, a);
analogWrite(g, a);
delay(10);
}
}
void gp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(g, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(g, a);
delay(10);
}
}
void gbp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(g, a);
analogWrite(b, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(g, a);
analogWrite(b, a);
delay(10);
}
}
void bp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(b, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(b, a);
delay(10);
}
}
void rbp()
{
for ( int a=0;a<=200;a++)
{
analogWrite(b, a);
analogWrite(r, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(b, a);
analogWrite(r, a);
delay(10);
}
}
void witep()
{
for ( int a=0;a<=200;a++)
{
analogWrite(b, a);
analogWrite(r, a);
analogWrite(g, a);
delay(10);
}
for ( int a=200;a>=0;a--)
{
analogWrite(r, a);
analogWrite(g, a);
analogWrite(b, a);
delay(10);
}
}
void loop()
{
long randNumber2;
long randNumber3;
for ( int a = 0;a<=25;a++)
{
randNumber2 = random(7);
switch(randNumber2)
{
case 1:re();break;
case 2:gr();break;
case 3:bl();break;
case 4:rg();break;
case 5:rb();break;
case 6:gb();break;
case 7:wite();break;
}
}
for ( int a = 0;a<=2;a++)
{
randNumber3 = random(7);
switch(randNumber3)
{
case 1:rp();break;
case 2:bp();break;
case 3:gp();break;
case 4:rgp();break;
case 5:gbp();break;
case 6:rbp();break;
case 7:wite();break;
}
}
}
|
|