I was Following the project
https://create.arduino.cc/projecthub/debanshudas23/getting-started-with-stepper-motor-28byj-48-3de8c9?f=1#comments
on arduino project hub, and the code it gave to turn the motor is
#define A 2
#define B 3
#define C 4
#define D 5
#define NUMBER_OF_STEPS_PER_REV 512
void setup(){
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
pinMode(C,OUTPUT);
pinMode(D,OUTPUT);
}
void write(int a,int b,int c,int d){
digitalWrite(A,a);
digitalWrite(B,b);
digitalWrite(C,c);
digitalWrite(D,d);
}
void onestep(){
write(1,0,0,0);
delay(5);
write(1,1,0,0);
delay(5);
write(0,1,0,0);
delay(5);
write(0,1,1,0);
delay(5);
write(0,0,1,0);
delay(5);
write(0,0,1,1);
delay(5);
write(0,0,0,1);
delay(5);
write(1,0,0,1);
delay(5);
}
void loop(){
int i;
i=0;
while(i<NUMBER_OF_STEPS_PER_REV){
onestep();
i++;
}
I was able to make the motor go backwards by writing there onestep function backwards, and ill leave that at he bottom, but I am trying to figure out how to make it go forwards, delay, backwards. Everything that I try seems like its going forwards and backwards at the same time.
Please help me out
void backstep()
{
write(1,0,0,1);
delay(1);
write(0,0,0,1);
delay(1);
write(0,0,1,1);
delay(1);
write(0,0,1,0);
delay(1);
write(0,1,1,0);
delay(1);
write(0,1,0,0);
delay(1);
write(1,1,0,0);
delay(1);
write(1,0,0,0);
delay(1);
}