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:
COM6
Autoscroll
Clear output
9600 baud
Newline
- The result on Serial Monitor:
COM6
I received: H
I received: E
I received: L
I received: L
I received: O
I received:
Autoscroll
Clear output
9600 baud
Newline
※ 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.