Hi together
I am working on a project in which I am trying to set the speed of 4 individual stepper motors by 4 potentiometers, each assigned to one single stepper motor. I have managed to wire everything correctly and it worked perfectly with one potentiometer and one stepper motor.
Now that I have put everything together with 4 stepper motors, 4 A4988 and 4 potentiometers, all of the stepper motors are only responding to the first potentiometer (A0).
Here is my code, which I have collected from various examples on the Internet and which worked fine for 1 stepper and 1 poti, but my logical multiplication of all variables and function does not seem to work properly.
const int step1 = 7;
const int dir1 = 8;
const int step2 = 5;
const int dir2 = 6;
const int step3 = 3;
const int dir3 = 4;
const int step4 = 1;
const int dir4 = 2;
int poti1, poti2, poti3, poti4, poti1map, poti2map, poti3map, poti4map;
void setup() {
pinMode(step1, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(step2, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(step3, OUTPUT);
pinMode(dir3, OUTPUT);
pinMode(step4, OUTPUT);
pinMode(dir4, OUTPUT);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, HIGH);
digitalWrite(dir3, HIGH);
digitalWrite(dir4, HIGH);
}
void loop() {
poti1map = speed1Up();
digitalWrite(step1, HIGH);
delayMicroseconds(poti1map);
digitalWrite(step1, LOW);
delayMicroseconds(poti1map);
poti2map = speed2Up();
digitalWrite(step2, HIGH);
delayMicroseconds(poti2map);
digitalWrite(step2, LOW);
delayMicroseconds(poti2map);
poti3map = speed3Up();
digitalWrite(step3, HIGH);
delayMicroseconds(poti3map);
digitalWrite(step3, LOW);
delayMicroseconds(poti3map);
poti4map = speed4Up();
digitalWrite(step4, HIGH);
delayMicroseconds(poti4map);
digitalWrite(step4, LOW);
delayMicroseconds(poti4map);
}
int speed1Up() {
int poti1 = analogRead(A0);
int new1Custom = map(poti1, 0, 1023, 300, 4000);
return new1Custom;
}
int speed2Up() {
int poti2 = analogRead(A1);
int new2Custom = map(poti2, 0, 1023, 300, 4000);
return new2Custom;
}
int speed3Up() {
int poti3 = analogRead(A2);
int new3Custom = map(poti3, 0, 1023, 300, 4000);
return new3Custom;
}
int speed4Up() {
int poti4 = analogRead(A3);
int new4Custom = map(poti4, 0, 1023, 300, 4000);
return new4Custom;
}
My final question would be: As I want the stepper motors to stop when the Potentiometers are at 0, I know that I have to define ditigalwrite(stepX; LOW) and the delaymicroseconds() to be at infinitely high, but is there a code for that or do I define it in the int speedXUp() Function?
Thanks for your help in advance!