iam a new comer in arduino. curently learning through the examples. now iam learning the 'the case switch 2 statement. i need to send a char ' on' from serial port and to on an led. how can be this done.the practical problem is that i couldnt type more than a letter in the case statement. eg- case'on':
Compare the input to the required string using memcmp() and use if/else to do the comparison based on the result.
i need to send a char ' on'
Post a picture of your keyboard with the on key circled, please.
If you can't, because your keyboard doesn't have an on key, then you need to reconsider what you are trying to do. In my case, my keyboard doesn't have an on key, so I would have to send two characters, 'o' and 'n', followed by some kind of delimiter (such as a carriage return), and have the Arduino read and store input until the delimiter arrived.
You have a choice to make. You must either make all your commands a single character or you must not use switch / case and use If / else if statements instead.
You could also build a table of acceptable commands, along with a corresponding constant, then have a function that returns the constant for any command parsed. Then, you can use the constant in a switch statement.
const byte COMMAND_UNKNOWN = 0;
const byte COMMAND_ON = 1;
const byte COMMAND_OFF = 2;
const byte COMMAND_STOP = 3;
int getCommandValue(char *command)
static _command commands =
for (int i=0; i < sizeof(commands)/sizeof(command); i++)
if (strcmp(commands[i].command, command) == 0)
char command = "on";