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