如何让我的 arduino 打印 "the loop is running for the ....... time"?
How can I make my arduino print "the loop is running for the ....... time"?
我想让我的arduino告诉我现在几点运行 "this is the 22nd time this loop has run." 我应该使用什么 command/s?
我目前正在使用此代码:
Serial.print("This loop has run ");
Serial.print(loopsRun);
Serial.println(" times.");
loopsRun++;
是的,我已经声明了所有变量,我只是想知道是否有办法检查任何 int 的最后一位数字。
22 % 10 = 2 你会说 22'nd'
1022 % 10 = 2 你会说 1022 'nd'
27 % 10 = 7 你会说 7 'th'
457 % 10 = 7 你会说 457 'th'
我的模式正确吗?如果是这样,那么您需要一个 switch 语句和一个 % operator
unsigned int remainder = loopsRun % 10;
switch (remainder)
{
case 0: suffix = "th"; break;
case 1: suffix = "st"; break;
case 2: suffix = "nd"; break;
<etc>
}
我想让我的arduino告诉我现在几点运行 "this is the 22nd time this loop has run." 我应该使用什么 command/s? 我目前正在使用此代码:
Serial.print("This loop has run ");
Serial.print(loopsRun);
Serial.println(" times.");
loopsRun++;
是的,我已经声明了所有变量,我只是想知道是否有办法检查任何 int 的最后一位数字。
22 % 10 = 2 你会说 22'nd' 1022 % 10 = 2 你会说 1022 'nd'
27 % 10 = 7 你会说 7 'th' 457 % 10 = 7 你会说 457 'th'
我的模式正确吗?如果是这样,那么您需要一个 switch 语句和一个 % operator
unsigned int remainder = loopsRun % 10;
switch (remainder)
{
case 0: suffix = "th"; break;
case 1: suffix = "st"; break;
case 2: suffix = "nd"; break;
<etc>
}