Simple programmable toy?

A note about command processing.

You may use if..else or switch statements of course. I suggest more elegant solution using arrays.

If you understand the solution with arrays, then processing commands can be implemented in the similar way.
Suppose you have 3 commands. Each command will have its unique id starting form 0 (zero) to 2.
You can store a function that will execute the command in the array;

// This function will execute command 0
void exec_command0()
{
}

void exec_command1()
{
}
// This function will execute command 2
void exec_command2()
{
}

// Note that all above functions have the same prototype: they receive void and return void
// We now need to define a type of this functions
typedef void (*command_executor_type)();

// Now we define array of those functions
command_executor_type exec_commands[] =
{
    exec_command0,
    exec_command1,
    exec_command2
};

Now, in order to run the command, according it's id

  1. first access the corresponding array entry using '[ ]'. for command with id 0 (zero) it would be
    exec_commands[0]
  2. The entry, stored in the entry of array is function (actually the address of function, but that does not matter). We call functions using '()':
    exec_commands0;
void loop()
{
    char curr_command = 0; // get command id here 0-2
    
    // execute the command
    exec_commands[curr_command]();
}