![arduino serial library execute script arduino serial library execute script](https://user-images.githubusercontent.com/17074014/60776335-66139f00-a123-11e9-9976-79b5884511be.png)
Serial.println("Welcome to this simple Arduino command line interface (CLI).") The cli_init() function which is called in setup() just displays a short welcome message while my_cli() is where the the magic starts to happen.
![arduino serial library execute script arduino serial library execute script](https://i1.wp.com/descubrearduino.com/wp-content/uploads/2019/01/arduino-libraries.jpg)
When the user enters a command, the program will compare it to the strings in commands_str and call the function in commands_func with the same index. Int num_commands = sizeof(commands_str) / sizeof(char *) List of functions pointers corresponding to each command Int blink_cycles = 10 //How many times the LED will blink #define MAX_NUM_ARGS 8 //Maximum number of arguments #define ARG_BUF_SIZE 64 //Maximum argument string length #define LINE_BUF_SIZE 128 //Maximum input string length
![arduino serial library execute script arduino serial library execute script](https://i.stack.imgur.com/eOunJ.png)
Let’s start with the global variables, defines and the setup() and loop() functions.
#Arduino serial library execute script code
The code itself is just over 200 lines where many are just pure printing functions, so the core functionality is not that complex. We’ve also included a help command which explains what each command does as well as an exit command which just puts the program in a while(1) state. You can either turn it on, off or having it blink 10 times at a given frequency. The primary purpose of this specific code is to control the on-board LED tied to pin 13 on the Arduino. But first we’ll briefly explain what our program does. We’re basically going to go quickly go through the code in chunks in this post. The purpose of a CLI like this on an Arduino is to have the ability to send text commands to it during runtime to execute certain tasks, such as controlling a servo, displaying text on a screen or launching a rocket. What our CLI looks like in Arduino’s serial monitor.