소스1 -LED는 13에 연결 [도구-시리얼모니터]에서 1, 2, 3 을 입력해보세요 이외의 입력을 하면 나오는 부분은 어디일까요? 찾아보세요!-
const unsigned int LED_PIN = 13;
const unsigned int BAUD_RATE = 9600;
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(BAUD_RATE); // <label id="code.welcome.init_serial"/>
}
void loop() {
if (Serial.available() > 0) { // <label id="code.welcome.available"/>
int command = Serial.read();
if (command == '1') {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED on");
} else if (command == '2') {
digitalWrite(LED_PIN, LOW);
Serial.println("LED off");
} else if (command == '3'){
Serial.println("light");
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
delay(500);
} else {
Serial.print("Unknown command: ");
Serial.println(command); // <label id="code.welcome.print_formats"/>
}
}
}
'작업실 > arduino' 카테고리의 다른 글
아두이노(arduino) - 7세그먼트(segment)에 각기 다른 숫자를 표현해보자 (0) | 2015.03.06 |
---|---|
아두이노(arduino) - 가변저항에 의해 조절되는 LED (0) | 2015.03.06 |
아두이노(arduino) - 스피커를 이용한 음악연주 (0) | 2015.03.06 |
아두이노(arduino) - 릴리즈되는 스위치로 LED를 켜고 끄자 (0) | 2015.03.06 |
아두이노(arduino) - 스위치로 LED켜고 끄기 (0) | 2015.03.06 |