Serial.write()

Description

Ecrit des données binaires sur le port série. Ces données sont envoyées comme une série d'octet; pour envoyer les caractères correspondants aux chiffres d'un nombre, utiliser plutôt la fonction print().

Syntaxe

Serial.write(val) Serial.write(str) Serial.write(buf, len)

Paramètres

  • val: une valeur à envoyer sous forme d'octet simple
  • str: une chaîne à envoyer sous forme d'une série d'octets
  • buf: un tableau pour envoyer une série d'octets
  • len: la largeur du tableau

Exemple

void setup() { Serial.begin(9600); Serial.write(45); // write a byte with the value 45 => '-' character Serial.write('\n'); // write a newline character Serial.write("ArduinoGetStarted.com\n"); // write a string terminated by a newline character byte buf[] = {'A', 'r', 'd', 'u', 'i', 'n', 'o'}; Serial.write(buf, 7); // write an array } void loop() { }
  • 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
- ArduinoGetStarted.com Arduino
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