How to make 1 command be interpretted as multiple

I am making a chess program and I want to type something like e6e7 into the terminal. Is it possible to make the bot know to move from e6 to e7 with only input into the serial monitor

Welcome to the forum

The answer to your question is yes. The program can interpret the 2 character input as 2 separate commands

void setup()
{
  Serial.begin(115200);
  char input[] = {"e6e7"};
  char from[3];
  sprintf(from, "%c%c", input[0], input[1]);
  char to[3];
  sprintf(to, "%c%c", input[2], input[3]);
  Serial.print("moving from ");
  Serial.print(from);
  Serial.print(" to ");
  Serial.println(to);
}

void loop()
{
}

not sure what you mean by 'bot, a chess program running on arduino?

consider following to reading "moves" thru serial monitor

char col [2];
int  row [2];
char s [80];

void
process (void)
{
    sprintf (s, "move %c%d to %c%d", col [0], row [0],  col [1], row [1]); 
    Serial.println (s);
}

void
loop (void)
{
    if (Serial.available ())  {
        char buf [80];
        int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-1);
        buf [n] = '\0';

        sscanf (buf, "%c%d%c%d", &col [0], &row [0],  &col [1], &row [1]); 
        process ();
    }
}

void
setup (void)
{
    Serial.begin (9600);
}

I am still a bit new what is the purpose of the "char input" at the start and how would I change it to accept any 4 character command?

1 Like

(post deleted by author)

Get the code and add some print statements and other debugging techniques , so you can see what is happening with variables and what is happening .
It’s not easy to modify someone else’s code unless it’s well documented and well written ( then still hard) .
You need to put the code up here , but it’s a long shot for someone to trawl through a load of code .

@jakethejeff ,

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

For the example it is an array to hold the value to be split into 2

As to actually reading input from a user see Serial input basics - updated

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.