Hello everyone,
I am using a function to control a stepper motor driven actuator different distances and directions. the function is taking two inputs one for direction where HIGH means down and LOW means up, and another variable for the distance moved in mm. I was wondering how I could put something in the function so instead of typing HIGH or low for an input I could type up or down. I was also wondering if there is a way I could have a third variable to decide which motor to use. each motor however uses different pins and moves in a different direction given HIGH/LOW, so those would need to change depending on the third variable.
// defines pins numbers
const int stepPina = 6;
const int dirPina = 5;
const int enPina = 7;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPina,OUTPUT);
pinMode(dirPina,OUTPUT);
pinMode(enPina,OUTPUT);
digitalWrite(enPina,LOW);
}
void loop() {
movemotor(10, LOW);
delay(500);
}
//motor simplification function
void movemotor(int dist, int dir) {
dist = dist*100;
digitalWrite(dirPina, dir); // Enable particular direction
for(int x = 0; x < dist; x++) {
digitalWrite(stepPina,HIGH);
delayMicroseconds(500);
digitalWrite(stepPina,LOW);
delayMicroseconds(500);
}
}
thank you for any help