Sorry for not simply posting the code, I was unaware how. I have made the semi-colon correction.
//In this sketch I wish to control a stepper motor using my Arduino Mega 2560 R3, utilizing four push button switches.
#define DIR 22 //setting the direction output of stepper (DIR) to pin 22
#define STP 2 //setting steps output of stepper motor (STP) to pin 2
#define PB1 25 //setting input of push button switch one (PB1) to pin 25
#define PB2 26 //setting input of push button switch two (PB2) to pin 26
#define PB3 27 //setting input of push button switch three (PB3) to pin 27
#define PB4 28 //setting input of push button switch four (PB4) to pin 28
void setup()
{
pinMode(DIR, OUTPUT);
pinMode(STP, OUTPUT);
pinMode(PB1, INPUT);
digitalWrite(PB1, HIGH);
pinMode(PB2, INPUT);
digitalWrite(PB2, HIGH);
pinMode(PB3, INPUT);
digitalWrite(PB3, HIGH);
pinMode(PB4, INPUT);
digitalWrite(PB4, HIGH);
}
void loop()
{
byte a=!digitalRead(PB1);
byte b=!digitalRead(PB2);
byte c=!digitalRead(PB3);
byte d=!digitalRead(PB4);
int stepperPosition0=400;
int stepperPosition1=(stepperPosition0+400);
int stepperPosition2=(stepperPosition1+400);
int stepperPosition3=(stepperPosition2+400);
if (a==1) //if PB1 is pressed
{
digitalWrite(STP,stepperPosition0); //stepper motor will go to position 0
}
else if (b==1) //unless PB2 is pressed
{
digitalWrite(STP,stepperPosition1); //then stepper motor will go to position 1
}
else if (c==1) //unless PB3 is pressed
{
digitalWrite(STP,stepperPosition2); //then stepper motor will go to position 2
}
else if (d==1) //unless PB4 is pressed
{
digitalWrite(STP,stepperPosition3); //then stepper motor will go to position 3
}
}
Can anyone tell me if I'm sending the signal to the EasyDriver Stepper Motor Driver correctly so that the stepper motor will actually move? I feel as if the 400 micro step increments are unit-less in the code I have written and my Arduino will not know what to do with that value. Will it essentially ask "400 what?", and if so, how can I assign 400 a unit so it realizes what action to carryout.