执行系列命令
Executing commands in Series
这是我的arduino代码。在receive command下面放置什么来控制一系列操作过程中命令的执行?提前谢谢你。
void loop(void)
{
char cmd(C,S,V,T);
//what do i put here//
if (cmd=='C')
Serial.println("complete");
if (cmd=='S')
Serial.println("incomplete");
else if (cmd=='V')
Serial.println("wrong");
else if (cmd=='T')
Serial.println("correct");
else
Serial.println("retry");
}
这行得通;我刚刚试过了。
void setup()
{
Serial.begin(9600);
Serial.setTimeout(100); //don't wait longer than 100ms for incoming data
}
void loop(void)
{
char cmd;
if (Serial.available())
{
cmd = Serial.read();
if (cmd == 'C')
{
Serial.println("complete");
}
else if (cmd == 'S')
{
Serial.println("incomplete");
}
else if (cmd == 'V')
{
Serial.println("wrong");
}
else if (cmd == 'T')
{
Serial.println("correct");
}
else
{
Serial.println("retry");
}
}
}
这是我的arduino代码。在receive command下面放置什么来控制一系列操作过程中命令的执行?提前谢谢你。
void loop(void)
{
char cmd(C,S,V,T);
//what do i put here//
if (cmd=='C')
Serial.println("complete");
if (cmd=='S')
Serial.println("incomplete");
else if (cmd=='V')
Serial.println("wrong");
else if (cmd=='T')
Serial.println("correct");
else
Serial.println("retry");
}
这行得通;我刚刚试过了。
void setup()
{
Serial.begin(9600);
Serial.setTimeout(100); //don't wait longer than 100ms for incoming data
}
void loop(void)
{
char cmd;
if (Serial.available())
{
cmd = Serial.read();
if (cmd == 'C')
{
Serial.println("complete");
}
else if (cmd == 'S')
{
Serial.println("incomplete");
}
else if (cmd == 'V')
{
Serial.println("wrong");
}
else if (cmd == 'T')
{
Serial.println("correct");
}
else
{
Serial.println("retry");
}
}
}