Serial.read()
설명
들어오는 시리얼 데이터를 읽는다. read()는 Stream utility class 로부터 상속받는다.
문법
Serial.read()
Arduino Mega only:
Serial1.read()
Serial2.read()
Serial3.read()
매개변수
- 없음
반환값
- 들어온 데이터의 첫 바이트 사용가능(또는 사용할 데이터 없으면 -1). 데이터 유형: int.
예제 코드
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// prints the received data
Serial.print("I received: ");
Serial.println((char)incomingByte, DEC);
}
}
- Type "HELLO" on Serial Monitor and click Send button:
COM6
Autoscroll
Clear output
9600 baud
Newline
- 시리얼 모니터에 결과:
COM6
I received: H
I received: E
I received: L
I received: L
I received: O
I received:
Autoscroll
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 - Serial
- 언어 : Serial.available()
- 언어 : Serial.begin()
- 언어 : Serial.end()
- 언어 : Serial.find()
- 언어 : Serial.findUntil()
- 언어 : Serial.flush()
- 언어 : if(Serial)
- 언어 : Serial.parseFloat()
- 언어 : Serial.parseInt()
- 언어 : Serial.peek()
- 언어 : Serial.print()
- 언어 : Serial.println()
- 언어 : Serial.readBytes()
- 언어 : Serial.readString()
- 언어 : serialEvent()
- 언어 : Serial.setTimeout()
- 언어 : Serial.write()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.
Additionally, some links direct to products from our own brand, DIYables.