Serial.read()

Descripción

Lee los datos de la entrada serie. read() ihereda de la clase Stream.

Sintaxis

Serial.read()

Solo Arduino Mega:

Serial1.read()

Serial2.read()

Serial3.read()

Parámetros

  • Ninguno

Retornos

  • El primer byte disponible de los datos de la entrada serie (o -1 si no hay datos disponibles) - int

Ejemplo

int incomingByte = 0; // para la entrada de datos serie void setup() { Serial.begin(9600); // abre el puerto serie, configura los datos a 9600 bps } void loop() { // envia datos sólo cuando se reciben datos: if (Serial.available() > 0) { // lee el byte de entrada: incomingByte = Serial.read(); // di lo que tienes: Serial.print("I received: "); Serial.println((char)incomingByte, DEC); } }
  • Type "HELLO" on Serial Monitor and click Send button:
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
Ln 11, Col 1
Arduino Uno on COM15
2
  • The result on Serial Monitor:
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
I received: H I received: E I received: L I received: L I received: O I received:
Ln 11, Col 1
Arduino Uno on COM15
2

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 .

※ OUR MESSAGES