Because you used the Arduino IDE's Auto Format on your code, the indentation provides a nice visual representation of the program structure. If you carefully study the indentation of the printMove() function, I think you'll see the problem. This is a very useful troubleshooting technique.
After 313 posts, don't you think it is time you posted the actual error messages the IDE returns?
To expand on what @pert hinted, if, after auto-format, a function definition doesn't start on the extreme left, you've done something wrong.
In this case you've tried to define a function inside another function.
C++ doesn't allow that.
Thanx, that problem is solved now.
But now thw switch function part is never reached.
P.S. I am visual handicapt, some websites and the arduino IDE are not perfect. Sorry fo my handicap
const byte KEY_ESC =0x1B;
const byte KEY_MOVE =0x5B;
const byte KEY_NORHT =0x41; // A
const byte KEY_SOUHT =0x42; // B
const byte KEY_EAST =0x43; // C
const byte KEY_WEST =0x44; // D
boolean recvCommand = false;
void setup()
{
Serial.begin(9600);
delay(200); // Give Serial Monitor time to connect, which causes a reset.
Serial.println("Enter Command: ");
Serial.println("BIN\tOCT\tDEC\tHEX");
}
void loop()
{
int c = Serial.read(); // note read() returns an int, char c = converts it to a char
if (c != -1) // .read() return -1 if there is nothing to be read.
{
// got a char show it
Serial.print (c, BIN);
Serial.print("\t");
Serial.print(c, OCT);
Serial.print("\t");
Serial.print(c, DEC);
Serial.print("\t");
Serial.print(c, HEX);
Serial.print("\t");
Serial.println((char)c);
recvCommand = true;
}
if (recvCommand == true && c == KEY_ESC)
{
Serial.println(" Got Escape key");
recvCommand = false;
}
else if (recvCommand == true && c == KEY_MOVE)
{
Serial.println(" Got move key");
delay(10); // Give a little time for character to be received
int m = Serial.read(); // note read() returns an int, char c = converts it to a char
switch (m)
{
case KEY_NORHT:
printMove("Norht");
break;
case KEY_SOUHT:
printMove("SOUHT");
break;
case KEY_EAST:
printMove("EAST");
break;
case KEY_WEST:
printMove("WEST");
break;
}
recvCommand = false;
}
else if (recvCommand == true)
{
Serial.println("Decode other key");
recvCommand = false;
}
}
void printMove(const char *str1)
{
Serial.print("Move dish ");
Serial.println(str1);
recvCommand = false;
}