Serial.read()
Description
Lit les données entrantes sur le port Série.
Syntaxe
Serial.read();
Paramètres
- Aucun
Valeurs Renvoyées
- Renvoi le premier octet de donnée entrant disponible dans le buffer du port série, ou -1 si aucune donnée n'est disponible. (int)
※ Remarque:
L'octet lu est « enlevé » de la file d'attente. Le prochain appel de la fonction read() lira l'octet suivant, etc...
Exemple
int incomingByte = 0; // variable pour lecture de l'octet entrant
void setup() {
Serial.begin(9600); // ouvre le port série et fixe le débit à 9600 bauds
}
void loop() {
// envoie une donnée sur le port série seulement quand reçoit une donnée
if (Serial.available() > 0) { // si données disponibles sur le port série
// lit l'octet entrant
incomingByte = Serial.read();
// renvoie l'octet reçu
Serial.print("Octet recu: ");
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
Octet recu: H
Octet recu: E
Octet recu: L
Octet recu: L
Octet recu: O
Octet recu:
Autoscroll
Clear output
9600 baud Â
Newline Â
※ Remarque:
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)
Voir Également
- Langage: Arduino - Serial
- Langage: Serial.available()
- Langage: Serial.begin()
- Langage: Serial.find()
- Langage: Serial.findUntil()
- Langage: Serial.flush()
- Langage: Serial.parseFloat()
- Langage: Serial.parseInt()
- Langage: Serial.peek()
- Langage: Serial.print()
- Langage: Serial.println()
- Langage: Serial.readBytes()
- Langage: Serial.readBytesUntil()
- Langage: Serial.setTimeout()
- Langage: Serial.write()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
Follow Us