ARDUINO-RGB灯实验
2022/08
20
13:08
接线方式:
RGB3口直接接9,10,11号,GND接GND口即可
#define RGB_RED 9
#define RGB_GREEN 10
#define RGB_BLUE 11
void setup()
{
pinMode(RGB_RED,OUTPUT);
pinMode(RGB_GREEN,OUTPUT);
pinMode(RGB_BLUE,OUTPUT);
}
void setColor(int red,int blue, int green)
{
analogWrite(RGB_RED,red);
analogWrite(RGB_GREEN,green);
analogWrite(RGB_BLUE,blue);
}
void loop()
{
int r = random(255);
int g = random(255);
int b = random(255);
setColor(r,g,b);
delay(250);
}
void loop2()
{
int i;
for(i=1; i<255; ++i)
{
setColor(i, 0, 0);
delay(1);
}
for(; i>=0; --i)
{
setColor(i, 0, 0);
delay(1);
}
for(i=1; i<255; ++i)
{
setColor(0, i, 0);
delay(1);
}
for(; i>=0; --i)
{
setColor(0, i, 0);
delay(1);
}
for(i=1; i<255; ++i)
{
setColor(0, 0, i);
delay(1);
}
for(; i>=0; --i)
{
setColor(0, 0, i);
delay(1);
}
setColor(0, 0, 0);
delay(8);
}
CopyRights: The Post by BY-NC-SA For Authorization,Original If Not Noted,Reprint Please Indicate From 老刘@开发笔记
Post Link: ARDUINO-RGB灯实验
Post Link: ARDUINO-RGB灯实验