Last active
December 27, 2015 03:48
-
-
Save laziu/7261817 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int LED1 = 1; | |
const int LED2 = 2; | |
const int LED3 = 3; | |
const int ON = 1; | |
const int OFF = 0; | |
const int LED1_pin = 2; //LED1을 연결한 아두이노 핀의 번호 | |
const int LED2_pin = 3; //LED2을 연결한 아두이노 핀의 번호 | |
const int LED3_pin = 4; //LED3을 연결한 아두이노 핀의 번호 | |
void setup() { | |
Serial.begin(9600); //시리얼 모니터와의 통신 주기를 1초에 9600번으로 지정한다. | |
pinMode(LED1_pin,OUTPUT); //LED1_pin을 출력으로 지정한다. | |
pinMode(LED2_pin,OUTPUT); //LED2_pin을 출력으로 지정한다. | |
pinMode(LED3_pin,OUTPUT); //LED3_pin을 출력으로 지정한다. | |
//LED 정상 여부를 확인한다. | |
digitalWrite(LED1_pin, HIGH); | |
delay(50); | |
digitalWrite(LED1_pin, LOW); | |
delay(50); | |
digitalWrite(LED2_pin, HIGH); | |
delay(50); | |
digitalWrite(LED2_pin, LOW); | |
delay(50); | |
digitalWrite(LED3_pin, HIGH); | |
delay(50); | |
digitalWrite(LED3_pin, LOW); | |
delay(50); | |
delay(200); | |
} | |
int r, g, b; | |
int randNumber; | |
void loop() | |
{ | |
//r, g, b 값에 새로 밝힐 색을 저장한다. | |
r = random(0, 255); //범위를 24bit컬러로 한정하여 한 색당 0~255로 제한 | |
g = random(0, 255); | |
b = random(0, 255); | |
Serial.print(r,DEC); //Serial 통신으로 r, g, b를 출력 | |
Serial.print(g,DEC); | |
Serial.print(b,DEC); | |
Serial.println(); | |
//색상에 맞춰 각각의 LED를 밝힌다. | |
analogWrite(LED1_pin, r); | |
analogWrite(LED2_pin, g); | |
analogWrite(LED3_pin, b); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment