serialEvent()
Descripción
Se llama cuando se dispone de datos. Utilice Serial.read(), Serial.readBytes(), Serial.readBytesUntil(), Serial.readString(), or Serial.readStringUntil() para capturar estos datos.
Sintaxis
void serialEvent() {
//instrucciones
}
Solo Arduino Mega:
void serialEvent1() {
//instrucciones
}
void serialEvent2() {
//instrucciones
}
void serialEvent3() {
//instrucciones
}
Parámetros
- instrucciones: cualquier instrucción válida.
Ejemplo
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
Autoscroll
Clear output
9600 baud
Newline
- The result on Serial Monitor:
COM6
I received: A
I received: r
I received: d
I received: u
I received: i
I received: n
I received: o
I received:
Autoscroll
Clear output
9600 baud
Newline
※ Nota:
- En la actualidad, serialEvent() no es compatible con el Esplora, Leonardo, o Micro
※ 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.