Hello everyone,
I'm looking to create an acceleration and deceleration code for a stepper motor.
Here you can find the code :
#define EN2 8
#define DIR2 9
#define ST2 10
void setup(){
pinMode(EN2, OUTPUT);
pinMode(DIR2, OUTPUT);
pinMode(ST2, OUTPUT);
Serial.begin(115200);
}
void loop(){
int D2 = 200;
while (true){
digitalWrite(EN2, HIGH);
digitalWrite(DIR2, HIGH);
float delay2 = ((1/D2)*1000000);
D2 += 100;
if (D2 > 3200){D2 = 3200;}
for (int i = 0; i <= 200; i++) {
digitalWrite(ST2, HIGH);
delayMicroseconds(delay2);
//delay(1);
digitalWrite(ST2, LOW);
//delay(1);
delayMicroseconds(delay2);}
}
}
After uploading this code, the stepper doesn't rotate despite hearing the sound of a continuous frequency.
And I want to specify that replacing "delay2" by 5000 the stepper rotating fine but without acceleration.
Any suggestion can help me.
Thank you in advance.