RGB LED 介紹
可以想像成有紅色(R) 綠色(G) 藍色(B)三色的LED共用一個陰極(-)。
使用 PWM(pulse width modulation)技術調出想要的顏色。
X1 Arduino Uno R3
X1 Common cathode RGB LED
X3 220 Ω 電阻
Arduino Code
int red=6;
int green=3;
int blue=5;
void setup()
{
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
}
void loop()
{
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
digitalWrite(blue,LOW);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
digitalWrite(blue,LOW);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(green,LOW);
digitalWrite(blue,HIGH);
delay(1000);
digitalWrite(red,HIGH);
digitalWrite(green,HIGH);
digitalWrite(blue,LOW);
delay(1000);
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
digitalWrite(blue,HIGH);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
digitalWrite(blue,HIGH);
delay(1000);
digitalWrite(red,HIGH);
digitalWrite(green,HIGH);
digitalWrite(blue,HIGH);
delay(1000);
}
沒有留言:
張貼留言