read()

Parent Previous Next

수신 버퍼에서 1바이트를 읽어 옵니다. 읽은 바이트는 수신 버퍼에서 삭제됩니다.

수신 버퍼에 데이터가 없을 경우 -1을 리턴합니다.


사용방법

Serial.read()


PC-4S, PC-7S 전용:

Serial1.read()

Serial2.read()

Serial3.read()


리턴값

int - 수신 버퍼에서 읽은 데이터


예제 코드

int incomingByte = 0;   // 데이터 저장용 변수


void setup() {

        Serial.begin(9600);

}


void loop() {


        // 데이터를 수신했을 때만 작동하도록

        if (Serial.available() > 0) {

                // 1바이트를 읽어옴

                incomingByte = Serial.read();


                // 읽은 바이트를 전송

                Serial.print("I received: ");

                Serial.println(incomingByte, DEC);

        }

}

Created with the Personal Edition of HelpNDoc: Write eBooks for the Kindle