-1

在此处输入图像描述

我需要将“任何东西”放入 tinkercad 上的串行监视器中并让它 print.ln 一次用一个字母返回(就像在第一张图片中一样),但我只是不明白它是如何完成的。我的大学在教学方面太没用了,我想放弃。

void setup()
{
    Serial.begin(9600);
  
}

void loop()
  
 //char something = a;
 char myString[20];
  int index = 0;
  
  // Read characters from the input buffer
  while (Serial.available() > 0) {

    // Read the oldest byte in the serial buffer
    myString[index] = Serial.read();
    
   // myString[index] = {something};

    // Increment the index
    // index++;

    // Pause to allow data to come into the buffer
    delay(10);

  }

  
  // Print string from an array of characters
  for (int i = 0; myString[i] != 0; i++) {

    // Print the character
    // Serial.print(myString[i], BYTE); MS: amended 22/8/14
    Serial.print(myString[i]); 

  }
  

但我得到了错误:

在此处输入图像描述

有人请帮忙,我真的不明白这一点,它与python和C有很大不同。

4

0 回答 0