I implemented the RGB three-color light case based on the arduino UNO R3 kit. In this complete kit, there are RGB three-color light integrated devices.
As for the circuit principle of RGB three-color lamp, you can search it directly on the Internet, so I won’t go into details here. Next is an example of RGB three-color lights.
RGB three-color light - running water light effect:
#define RED 12
#define GREEN 8
#define BLUE 7
void red(void);
void green(void);
void blue(void);
void setup() {
// put your setup code here, to run once:
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, LOW);
digitalWrite(RED, LOW);
digitalWrite(RED, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
red();
delay(1000);
green();
delay(1000);
blue();
delay(1000);
}
void red(void)
{
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
}
void green(void)
{
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, LOW);
}
void blue(void)
{
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, HIGH);
}
RGB three-color light - breathing light effect:
#define LED_red 11
#define LED_green 10
#define LED_blue 9
void breath(int pin);
void setup() {
// put your setup code here, to run once:
pinMode(LED_red, OUTPUT);
pinMode(LED_green, OUTPUT);
pinMode(LED_blue, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
breath(LED_red);
breath(LED_green);
breath(LED_blue);
}
void breath(int pin)
{
for(int i = 0; i <= 255; i++)
{
analogWrite(pin, i);
delay(5);
}
for(int i = 255; i >= 0; i--)
{
analogWrite(pin, i);
delay(5);
}
delay(100);
}
Here I would like to remind everyone: on the Arduino UNO board, there is a pwm output port, you need to pay attention to it, and here I use the analogWrite(int pin, int value) function, which is specially used for pwm debugging output in the arduino function library. of.