“Lesson 7--Microduino “RGB LED””的版本间的差异
Jasonsheng(讨论 | 贡献) (Created page with "{| style="width: 800px;" |- | ==Objective== You have learned several LED experiment, then go on studying the RGB LED that is display different color by a RGB LED, including th...") |
Jasonsheng(讨论 | 贡献) |
||
第17行: | 第17行: | ||
RGB LED contains three LEDs, one is red, the other is green and another it blue. | RGB LED contains three LEDs, one is red, the other is green and another it blue. | ||
By controlling three LED's brightness, you can mix up almost any color you want. | By controlling three LED's brightness, you can mix up almost any color you want. | ||
− | [[File: | + | [[File:lesson7-RGB.jpg|600px|center|thumb]] |
===Connection method=== | ===Connection method=== | ||
第25行: | 第25行: | ||
==Experimental schematic== | ==Experimental schematic== | ||
The following connection uses method 1 and uses D5,D6,D11. | The following connection uses method 1 and uses D5,D6,D11. | ||
− | [[File: | + | [[File:lesson7-schematic.jpg|600px|center|thumb]] |
==Program== | ==Program== |
2014年2月16日 (日) 08:07的版本
目录ObjectiveYou have learned several LED experiment, then go on studying the RGB LED that is display different color by a RGB LED, including the breathing lamp's effect. Equipment
RGBRGB LED contains three LEDs, one is red, the other is green and another it blue. By controlling three LED's brightness, you can mix up almost any color you want. Connection method
Experimental schematicThe following connection uses method 1 and uses D5,D6,D11. Program int redPin = 11;
int greenPin = 5;
int bluePin = 6;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow
delay(1000);
setColor(80, 0, 80); // Purple
delay(1000);
setColor(255, 255, 255);// White
delay(1000);
setColor(0, 0, 0); //Black
delay(1000);
for(int i=0;i<255;i+=5)//Red coming on
{
setColor(i, 0, 0);
delay(30);
}
delay(100);
for(int i=255;i>0;i-=5)//Red coming off
{
setColor(i, 0, 0);
delay(30);
}
delay(100);
for(int i=0;i<255;i+=5)//Blue coming on
{
setColor(0, i, 0);
delay(30);
}
delay(100);
for(int i=255;i>0;i-=5)//Blue coming off
{
setColor(0, i, 0);
delay(30);
}
delay(100);
for(int i=0;i<255;i+=5)//Green coming on
{
setColor(0, 0, i);
delay(30);
}
delay(100);
for(int i=255;i>0;i-=5)//Green coming off
{
setColor(0, 0, i);
delay(30);
}
delay(100);
}
void setColor(int red, int green, int blue)//Color display program
{
analogWrite(redPin, 255-red); //A total of anode RGB, low level light red LED
analogWrite(greenPin, 255-green);
analogWrite(bluePin, 255-blue);
}
Program custom setColor function and invoked in loop directly which make the program looks clean and clear. Here just list a few kinds of color, you can get color value through other colors modulus software, such as PhotoShop. ResultIn a light can be seen on red, green, blue, yellow, purple, black, white, and effect like a breathing lamp . Video |