준비물 : 브레드보드, 아두이노, RGB LED, 330Ω 저항 3개, M/M 점퍼선 6개
RGB LED는 핀이 4개인데요 제일 긴 부분(GND)을 기준으로 구분하시면 돼요
빨강, 초록, 파랑 부분이 다릅니다.
원래는 회로도 처럼 점퍼선을 색깔별로 잘 구분해야 하는데..
제가 M/M 점퍼선 여유분이 없어서ㅠㅠ 그냥 초록2개, 파랑2개, 흰색 2개로 했습니다.
(저는 빨간 선 부분을 흰 선으로 하고, 검정 선은 초록과 파랑으로 대체했습니다.)
RGB 핀에 해당하는 빨간 선은 9번, 초록 선은 10번, 파란 선은 11번에 꽂으시면 됩니다.
+에 해당하는 빨간선은 5V에 꽂으시고, -에 해당하는 까만선은 GND에 꽂습니다.
연결을 하면 이런 모습이 됩니다!
아두이노 스케치 프로그램을 실행 시킨 뒤, 입력후 업로드 버튼을 누르시면 됩니다!
// There are a few new programming features introduced in this lab.
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;
// The lines above make it easy to move wire leads to one of the other PWM pins
// (3,5 or 6) by changing one value in the code.
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;
const int DISPLAY_TIME = 100;
// Another constant that would make varying the delay easy to adjust.
void setup() {
// No setup required but you still need it
}
void loop(){
for (greenIntensity = 0; greenIntensity <= 255; greenIntensity+=5) {
redIntensity = 255-greenIntensity;
analogWrite(GREEN_LED_PIN, greenIntensity);
analogWrite(RED_LED_PIN, redIntensity);
delay(100);
}
// The analogWrite functions above are simulating voltage changes for the LED
// color changes. This will only work on the PWM pins.
for (blueIntensity = 0; blueIntensity <= 255; blueIntensity+=5) {
greenIntensity = 255-blueIntensity;
analogWrite(BLUE_LED_PIN, blueIntensity);
analogWrite(GREEN_LED_PIN, greenIntensity);
delay(100);
}
for (redIntensity = 0; redIntensity <= 255; redIntensity+=5) {
blueIntensity = 255-redIntensity;
analogWrite(RED_LED_PIN, redIntensity);
analogWrite(BLUE_LED_PIN, blueIntensity);
delay(100);
}
}
코드해석을 간단히 하면, R G B각 순서로 해당하는 영역에서
0.1초마다 세기를 0부터 255까지 1씩 증가 시키는 것입니다.
(0,0,0) -> (255,0,0) -> (255,255,0) -> (255,255,255)
제가 255개씩 다 쓸 수없으니 대충 이렇게 표현했는데요
빨주노초파남보를 보실 수 있습니다.
'컴퓨터공학 > 로봇 소프트웨어(Arduino)' 카테고리의 다른 글
[아두이노(Arduino)]실습 영상 (0) | 2017.07.05 |
---|---|
[EV3 Lego]종이비행기 발사대(A paper airplane launcher) (0) | 2017.07.05 |
[이론]EV3 LEGO PROGRAMMING (0) | 2017.07.05 |
3. 광센서를 이용해 야간등을 만들어보자(Cisco Lab 2.2.3.2 - Photo Resistor using Redboard and Arduino IDE) (0) | 2017.06.30 |
1. LED를 깜빡여보자(Cisco Lab 2.2.2.5 - Blinking an LED using RedBoard and Arduino IDE) (0) | 2017.06.30 |