Arduino

[Arduino] 아두이노 RGB LED 사용하기

Let it out 2024. 2. 2. 17:20

RGB LED란?

일반적인 led는 빨간색, 초록색, 흰색, 노란색 등 한가지 색만 나타낸다.
하지만 RGB Led는 하나의 Led에서 빨간색, 초록색, 초록색이 표현가능하며 색을 조합하여 여러가지 색상을 표현 할 수 있다. 또한 밝기 값도 조절이 가능다.
 

 

회로도

각각 선의 색깔이 R, G, B 센서를 제어한다.

 

 

 

 

코드 구현

1초에 한번씩 여러가지 색상을 출력한다..
#define R_PIN 8
#define G_PIN 9
#define B_PIN 10

void setup()
{
  Serial.begin(9600);
  pinMode(R_PIN, OUTPUT);
  pinMode(G_PIN, OUTPUT);
  pinMode(B_PIN, OUTPUT);
}
void loop()
{
  SetColor(255, 0, 0);// 빨강
  SetColor(0, 255, 0);//연두
  SetColor(0, 0, 255);//파랑
  SetColor(255, 255, 0);//노랑
  SetColor(80, 0, 80);//보라
}
void SetColor(int r, int g, int b)
{
  analogWrite(R_PIN, r);// rgb 색상 출력
  analogWrite(G_PIN, g);
  analogWrite(B_PIN, b);
  delay(1000);
}

반응형