pointing to an array

When I enter the code below and send "five_cw" from the serial monitor the serial print returns the 102,105,118 the first 3 ascii values of "five" I want it to return 1,150,100 I can't figure out the right syntax for the 3 lines similar to rot=((move_knee)[0]);

int five_ccw = {0,150,100}; //dir speed duration
int five_cw = {1,150,100}; //dir speed duration
int rot;
String move_knee; // for incoming serial data

void setup()

{
Serial.begin(9600);

}

void loop()
{
if (Serial.available() > 0)
{
move_knee = Serial.readString(); // read the incoming byte:
Serial.println(move_knee); //This line does return what I have entered into the serial monitor

rot=((move_knee)[0]);
rpm=((move_knee)[1]);
duration=((move_knee)[2]);

Serial.println(rot);
Serial.println(rpm);
Serial.println(duration);

}
}

Please post you original code and use code tags. The code you posted is defunct.

(why) (do you) (think) (you need so many) (parentheses?)

The simple answer here is that this is not possible in C.

The longer answer is that this requires introspection and dynamic features in a language, which is something that is generally only seen in scripting languages such as Python. And even there doing something like this is not encouraged.

I suggest that you reconsider the problem you are trying to solve and check if there might not be a better method to approach it. Perhaps using an array, map or hash table might be an alternative approach that works for you.

ensernet:
When I enter the code below and send "five_cw" from the serial monitor the serial print returns the 102,105,118 the first 3 ascii values of "five" I want it to return 1,150,100 I can't figure out the right syntax for the 3 lines similar to rot=((move_knee)[0]);

like this:

constexpr uint8_t MAX_MESSAGE_LENGTH = 32;  // check this!

int five_ccw [] = {0, 150, 100}; //dir speed  duration
int five_cw [] = {1, 150, 100}; //dir speed  duration
int rot;
//String move_knee;   // for incoming serial data

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

void loop() {
  if (const char* newMessage =  checkForNewMessage(Serial, '\n')) {
    Serial.println(newMessage);
    char* ptr = newMessage;
    int rotation = atoi(ptr);
    ptr = strchr(ptr, ',');
    int rpm = atoi(++ptr);
    ptr = strchr(ptr, ',');
    int duration = atoi(++ptr);
    Serial.println(rotation);
    Serial.println(rpm);
    Serial.println(duration);
  }
}

const char* checkForNewMessage(Stream& stream, const char endMarker)
{
  static char incomingMessage[MAX_MESSAGE_LENGTH] = "";
  static byte idx = 0;
  if(stream.available())
  {
    incomingMessage[idx] = stream.read();
    if(incomingMessage[idx] == endMarker)
    {
      incomingMessage[idx] = '\0';
      idx = 0;
      return incomingMessage;
    }
    else
    {
      idx++;
      if(idx > MAX_MESSAGE_LENGTH - 1)
      {
        //stream.print(F("{\"error\":\"message too long\"}\n"));  //you can send an error to sender here
        idx = 0;
        incomingMessage[idx] = '\0';
      }
    }
  }
  return nullptr;
}

five_cw only exists in your editor. Once you compile it, it changes to an address. You enter five_cw from the monitor, your code hasn't a clue what you're talking about. If you want to do like that you need a command parser.

Would this work?

String move_knee;   // for incoming serial data

void setup() 

{
  Serial.begin(9600);
  
}


void loop() 
  {
    if (Serial.available() > 0) 
        {  
          move_knee = Serial.readString(); // read the incoming byte:
           Serial.println(move_knee);   //This line does return what I have entered into the serial monitor
        
                 
        if (strcmp(move_knee, "five_cw")
       {
          rot = 1;
          rpm = 150;
          duration = 100;
       }

           Serial.println(rot);
           Serial.println(rpm);
           Serial.println(duration);

        }
}

evanmars - looks good.

I'd be inclined to enum a bunch inputs so as to use the int in a switch, assuming there'll be more than one command.

Probably enum the inputs then use that as an index into an arry holding values for rot, duration, and rpm.

Something like

class Command {
  char *name;
  int[3] values;
};
Command  commands[] = {
  {"five_ccw", {0,150,100}},
  {"five_cw", {1,150,100}}
};

you’d then scan the ‘commands’ array to find a command matching your input.

But, why use an array for dir, speed, duration? Wouldn’t it be better to name these things approporately?

class Command {
public:
  char *name;
  int dir, speed, duration;
};

Command commands[] = {
  {"five_ccw" ,0,150,100},
  {"five_cw", 1,150,100}
};

If you want to be able to rint these out to serial, add a method:

class Command {
public:
  char *name;
  int dir, speed, duration;
  void printMe() {
    Serial.print("[dir:");
    Serial.print(dir);
    Serial.print(", spd:");
    Serial.print(speed);
    Serial.print(", dur:");
    Serial.print(duration);
    Serial.print("]");
  }
}

Command  commands[] = {
  {"five_ccw" ,0,150,100},
  {"five_cw", 1,150,100}
};

void loop() {
  if (const char* newMessage =  checkForNewMessage(Serial, '\n')) {
    Serial.println(newMessage);
    boolean command_found = false;
    for(int i = 0; i<sizeof(commands)/sizeof(commands[0]); i++) {
      if(strcmp(newMessage, commands[i].name == 0) {
         commands[i].printMe();
         command_found = true;
         break;
      }
    }
    if(!command_found) {
      Serial.println("No matching command found.");
    }
  }
}

Of course, you could always stuff that strcmp() into a method inside the command class .

class Command {
public:
  char *name;
  int dir, speed, duration;

  void printMe() {
    Serial.print("[dir:");
    Serial.print(dir);
    Serial.print(", spd:");
    Serial.print(speed);
    Serial.print(", dur:");
    Serial.print(duration);
    Serial.print("]");
  }

  boolean matches(const char* s) {
    return strcmp(s, name)==0);
  }
}

void loop() {
…
    for(int i = 0; i<sizeof(commands)/sizeof(commands[0]); i++) {
      if(commands[i].matches(newMessage)) {
…

The advantage of that is that if there are multiple places in your code when you want to check for a match, they will all be doing it the same way. So if you decide to change things to make the match case-insensitive, or to ignore leading and trailing white space, you don’t need to update all of these multiple places to keep them consistent.