When I test following code, I hope it start to run after push button is pressed, but it always ran, means
push button didn't work at all? Can somebody check the code for me?
Thanks!
#define X_DIR 3
#define X_STP 4
int pushbuttonpin = 7; //Pin for momentary push button switch or sensor
int val=0;
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(50);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(800);
digitalWrite(stepperPin, LOW);
delayMicroseconds(800);
}
}
void setup(){
Serial.begin(9600);
pinMode(pushbuttonpin, INPUT); //Declare push button switch pin as input
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
}
void loop(){
val=digitalRead(pushbuttonpin);
if(val==HIGH)
{
step(true, X_DIR, X_STP, 800);
delay(1000);
step(false, X_DIR, X_STP, 400);
}
}