아두이노 serialEvent 인터럽트
2019. 7. 8. 14:48ㆍ드론
아두이노 프로그램 구조를 자세히 들여다보면
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for(;;) {
loop();
if(serialEvent) serialEvent();
}
}
무한루프에 진입하고나서, serialEvent를 검사하게 되는데 이 부분이 AVR에서의 인터럽트라고 생각하면 된다. 따라서 loop 밖에 serialEvent라고 함수를 작성해서 정의하면 그 함수는 시리얼통신이 들어왔을 때 인터럽트로 동작된다
주의할 점은 반드시 serialEvent라는 함수로 작성되어야만 한다
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
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
pinMode(13, OUTPUT); | |
} | |
void loop() { | |
} | |
void serialEvent(void) | |
{ | |
char data; | |
data = Serial.read(); | |
if(data == 'o') { | |
digitalWrite(13, 1); | |
} | |
else if(data == 'x') { | |
digitalWrite(13, 0); | |
} | |
} |
'드론' 카테고리의 다른 글
아두이노로 FND 6자리 출력하기 (0) | 2019.07.08 |
---|---|
아두이노 스위치 입력 한번만 받기 (0) | 2019.07.08 |
아두이노 LED 왕복해서 출력 (0) | 2019.07.08 |
아두이노 시리얼 모니터 새 줄과 line ending 없음 차이 (0) | 2019.07.08 |
아두이노 시리얼로 LED 출력 제어하기 (0) | 2019.07.08 |