serialEvent()

설명

데이터 사용이 가능할 때 호출됩니다. Serial.read() 함수가 이 데이터를 캡처하는 것에 사용합니다.

'serialEvent ()'기능은 모든 Arduino 보드 또는 'Serial'인터페이스에서 사용할 수 없습니다:

Board Available serialEvent() functions
Uno
Nano
serialEvent()
Mega serialEvent()
serialEvent1()
serialEvent2()
serialEvent3()
Leonardo
Micro
Yún
serialEvent1()
Uno WiFi Rev2
Nano Every
None
MKR boards
Nano 33 IoT
Zero
None
Nano 33 BLE None
Portenta H7 None
Due serialEvent()
serialEvent1()
serialEvent2()
serialEvent3()
101 serialEvent1()

문법

void serialEvent() { //statements }

추가 직렬 포트가있는 보드의 경우 (직렬 기본 페이지의 각 보드에 대해 사용 가능한 직렬 포트 목록 참조):

void serialEvent1() { //statements } void serialEvent2() { //statements } void serialEvent3() { //statements }

매개변수

  • statements: any valid statements

반환값

  • 없음

예제 코드

void setup() { Serial.begin(9600); } void loop() { } void serialEvent() { int incomingByte = Serial.read(); // prints the received data Serial.print("I received: "); Serial.println((char)incomingByte); }
  • Compile and upload the above code to Arduino
  • Type "Arduino" on Serial Monitor and click Send button:
COM6
Send
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • 시리얼 모니터에 결과:
COM6
Send
I received: A I received: r I received: d I received: u I received: i I received: n I received: o I received:
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ 주의 및 경고:

Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:

  • An Arduino board and other Arduino board
  • An Arduino board and other sensors/devices
  • An Arduino board and computer (any Serial software on computer)* An Arduino board and other Arduino board
  • An Arduino board and other sensors/devices
  • An Arduino board and computer (any Serial software on computer)

더보기

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES