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:
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
Octet recu: H Octet recu: E Octet recu: L Octet recu: L Octet recu: O Octet recu:
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