Arduino 各种模块篇 RGB LED灯

示例代码:

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

 

 

示例代码:

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

简单演示的代码。

可以显示多种颜色。

 

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

 

posted @ 2013-06-26 19:30  spaceship9  阅读(1627)  评论(0编辑  收藏  举报