Hi all.
There are so many users who want to send commands and parameters to arduino,
and let it to do different jobs according to the commands and parameters.
I also used to think so.
I found the hint (,or the answer itself) to implement a command processor in this book on chapter 9.
I translated the sample codes into a sketch called ProcessCommans.
The code is here.
The form of the commands is;
"the name of the command", "integer parameter";
where ,' separates the parameter value from the command's name and
;' terminates the command.
The name of the command is case-insensitive.
Since the white spaces are ignored, we can add them in a command line.
At the moment, the following three commands are implemented.
- help
prints the names of all the commands.
Arduino command processing example
help;
HELP
LED
BUZZER
- led
changes the brightness of the LED which is hooked up to the digital port #11.
Valid values of the parameter are 0 to 255.
led, 100;
LED command received.
parameter value is 100
led, 0x100;
LED command received.
parameter value is 256
wrong parameter value
led;
LED command received.
parameter value is 0
- buzzer
is a dummy command, only prints the parameter value.
buzzer, -50;
BUZZER command received.
parameter value is -50
We can send a negative value as an parameter.
In the next post, I'll show you how to add a new command and its function.