-
프로그램1-시리얼 통신2아두이노 2016. 7. 4. 22:08
아두이노 1.0에서 새롭게 추가된 serialEvent함수 이용.
serialEvent함수는 loop함수가 순환될때 마다 호출 된다.
//SerialRecive Serial event
const int ledPin =13;
int blinkRate =0;
void setup()
{
Serial.begin(9600); //9600으로 시리얼 포트 초기화
pinMode(ledPin,OUTPUT);
}
void loop()
{
blink();
}
void serialEvent()
{
while(Serial.available())
{
char ch = Serial.read();
Serial.write(ch);
if(isDigit(ch))
{
blinkRate = (ch - '0');
blinkRate = blinkRate*100;
}
}
}
void blink()
{
digitalWrite(ledPin,HIGH);
delay(blinkRate);
digitalWrite(ledPin,LOW);
delay(blinkRate);
}
'아두이노' 카테고리의 다른 글
시리얼 함수 (0) 2016.10.03 아두이노+ esp8266+DTH11 (0) 2016.09.19 DHT11 온도 습도 센서 (0) 2016.09.18 아두이노와 블루투스를 이용한 온도 습도 데이터 수집 (0) 2016.09.17 프로그램1-시리얼통신 (0) 2016.07.03