在 Arduino 中列印換行符和製表符


要列印換行符,你可以在文字中引入 '
' 字元,或者使用 Serial.println() 而不是 Serial.print()

示例程式碼如下 −

示例

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();
   Serial.print("This is line1
This is line2
");    Serial.println("This is line3");    Serial.println("This is line4"); } void loop() {    // put your main code here, to run repeatedly:     }

以上程式碼的序列埠監視器輸出為 −

輸出

要新增製表符,你可以在程式碼中引入 '\t'。

示例程式碼如下 −

示例

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();
   Serial.print("This is left half\tThis is right half
"); } void loop() {    // put your main code here, to run repeatedly:     }

相應的序列埠監視器輸出為 −

輸出

更新於: 23-Mar-2021

5K+ 檢視

開啟您的職業生涯

完成課程認證

立即開始
廣告