我如何对此代码进行添加以使用我的 arduino 打印一个完整的三角形

How can I make additions to this code to print a full triangle with my arduino?

本文关键字:打印 arduino 一个 三角形 我的 代码 添加      更新时间:2023-10-16

它显然只做了半个三角形,但我不知道如何解决这个问题。我是新手,老实说真的不知道如何使用它,所以帮助将不胜感激。我走到了这一步,但现在我迷路了:

void setup() 
{
  Serial.begin(9600);
  Serial.setTimeout(100000); // timeout now is 100 seconds
  // read a number from serial port
  String s = Serial.readStringUntil(10); // read a line from serial port
  int n = s.toInt(); // convert the input string to integer value
for (int i=0; i<n; i++){
  for (int j=0; j<i+1; j++){
    Serial.print("*" );
   }
Serial.print("n");
}
}
void loop(){
}

n 替换为行

for(int i = 1, k = 0; i <= rows; ++i, k = 0)
{
    for(space = 1; space <= rows-i; ++space)
    {
        cout <<"  ";
    }
    while(k != 2*i-1)
    {
        cout << "* ";
        ++k;
    }
    cout << endl;
}    

这里的输出

https://ideone.com/OPMeO1