Arduino 各种模块篇 RGB LED灯

时间:2023-02-05 03:43:25

示例代码:

类似与这样的led,共阴rgb led,通过调节不同的亮度,组合成不同的颜色。

Arduino 各种模块篇 RGB LED灯

Arduino 各种模块篇 RGB LED灯

示例代码:

/*
作者:极客工坊
时间:2012年12月18日
IDE版本号:1.0.1
发布地址:www.geek-workshop.com
作用:共阳RGB颜色循环
*/ int redPin = ;
int greenPin = ;
int bluePin = ; void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
} void loop()
{
setColor(, , ); // 红色
delay();
setColor(, , ); // 绿色
delay();
setColor(, , ); // 蓝色
delay();
setColor(, , ); // 黄色
delay();
setColor(, , ); // 紫色
delay();
setColor(, , ); // 浅绿色
delay();
} void setColor(int red, int green, int blue)
{
analogWrite(redPin, -red);
analogWrite(greenPin, -green);
analogWrite(bluePin, -blue);
}

简单演示的代码。

Arduino 各种模块篇 RGB LED灯

可以显示多种颜色。

更多关于此灯的链接:http://www.geek-workshop.com/forum.php?mod=viewthread&tid=2802