解決済み:
次を使用して、char バッファーを変更できます。
char *arg;
arg = SCmd.next();
int i;
sscanf(arg, "%d", &i);
Serial.print("String value ");
Serial.println(arg);
Serial.print("Integer value ");
Serial.println(i);
問題:
char バッファーの内容を格納された文字列から整数に変更する方法がわかりません。
例えば:
'1' は 1 でなければなりません。
'121' は 121 である必要があります
これが私が試したものです。
void doIt()
{
char *arg;
arg = SCmd.next(); // Get the next argument from the SerialCommand object buffer
if (arg != NULL) // As long as it existed, do it
{
int argInted = (int)arg; // Cast char arg* -> int argInted.
Serial.print("String value ");
Serial.println(arg);
Serial.print("Integer value ");
Serial.println(argInted); // Print this new found integer.
}
else {
Serial.println("Fix your arguements");
}
}
これが私が得たものです。毎回371に評価されます。私はポインターバッファーにさまざまなものを保存していますが、変換方法に関するアイデアはありますか?
Arduino Ready
> INPUT 1
String value 1
Integer value 371
> INPUT 2
String value 2
Integer value 371
> INPUT WHATSthisDO
String value WHATSthisDO
Integer value 371