三色LED RGB模块
使用三色全彩LED制造
模块有3个输出:
1.R,红色输出,
2.G,绿色输出,
3.B,蓝色输出.
模块特点:
3组信号输出,可通过单片机编程实现R,G,B三种颜色的混合达到全彩的效果,
实验代码:
intledPin = 13; // LED is connected to digital pin 13
intredPin = 11; // R petal on RGB LEDmodule connected to digital pin 11
intgreenPin = 9; // G petal on RGB LEDmodule connected to digital pin 9
intbluePin = 10; // B petal on RGB LEDmodule connected to digital pin 10
voidsetup()
{
pinMode(ledPin, OUTPUT); // sets theledPin to be an output
pinMode(redPin, OUTPUT); // sets theredPin to be an output
pinMode(greenPin, OUTPUT); // sets thegreenPin to be an output
pinMode(bluePin, OUTPUT); // sets thebluePin to be an output
}
voidloop() // run over and over again
{
// Basic colors:
color(255, 0, 0); // turn the RGB LEDred
delay(1000); // delay for 1second
color(0,255, 0); // turn the RGB LEDgreen
delay(1000); // delay for 1second
color(0, 0, 255); // turn the RGB LEDblue
delay(1000); // delay for 1second
// Example blended colors:
color(255,255,0); // turn the RGB LEDyellow
delay(1000); // delay for 1second
color(255,255,255); // turn the RGBLED white
delay(1000); // delay for 1second
color(128,0,255); // turn the RGB LEDpurple
delay(1000); // delay for 1second
color(0,0,0); // turn the RGB LEDoff
delay(1000); // delay for 1second
}
voidcolor (unsigned char red, unsigned char green, unsigned char blue) // the color generating function
{
analogWrite(redPin, 255-red);
analogWrite(bluePin, 255-blue);
analogWrite(greenPin, 255-green);
}