"cannot convert 'String' to 'uint8_t" Error

Hello,

I'm trying to use a function to activate one of the stepper motors I'm controlling with a Ramps 1.4, and I get this error. I'm using a string to pass the name of the motor I'm trying to move. The error is thrown by a digitalWrite function(digitalWrite(String(motor + "_STEP_PIN"), LOW);. The funny thing is that I'm calling digitalWrite 2 times before the line which throws the error and it seems to work fine.

The code is

#define X_STEP_PIN         54
#define X_DIR_PIN          55
#define X_ENABLE_PIN       38
#define X_MIN_PIN           3
#define X_MAX_PIN           2
int j=0;

void setup() {

  pinMode(X_STEP_PIN  , OUTPUT);
  pinMode(X_DIR_PIN    , OUTPUT);
  pinMode(X_ENABLE_PIN    , OUTPUT);
  digitalWrite(X_ENABLE_PIN    , LOW);

}
  void act_motor(String motor, int wait, boolean directie, int pasi) { 
  
for(int var1=0;var1<pasi;var1++){ 
    digitalWrite(String(motor + "_DIR_PIN"), directie); 
    digitalWrite(String(motor + "_STEP_PIN"), HIGH);
    delayMicroseconds(wait);
    digitalWrite(String(motor + "_STEP_PIN"), LOW);
    delayMicroseconds(wait);
  }
}

void loop () {
  if (j==0)
  act_motor("X",10,HIGH,100)
  j=1;}
}

Any ideas on what I'm doing wrong? I've read some of the other topics on this error and it seems that everybody is hating the String class :). I would switch to a different approach, but this one adds more clarity imho.

Thanks

 digitalWrite(String(motor + "_DIR_PIN"), directie);

the digitalWrite() function takes a uint8_t for the pin number and a unit8_t for the state, not a String.

From the digitalWrite function definition in wiring.digital.c:

void digitalWrite(uint8_t pin, uint8_t val)

The funny thing is that I'm calling digitalWrite 2 times before the line which throws the error and it seems to work fine.

and if you drag the upper end of the window that holds the error statements upwards ?

Any ideas on what I'm doing wrong?

Yes. Variables do NOT have names at run time. You can NOT construct a name, and expect the digitalWrite() statement to know what that name means.