Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int dirpin = 5;
- int steppin = 3;
- int buttonPin = 2; // the number of the pushbutton pin
- int direction = LOW;
- void setup() {
- pinMode(dirpin, OUTPUT);
- pinMode(steppin, OUTPUT);
- pinMode(buttonPin, INPUT);
- }
- void loop(){
- int buttonState = 0; // variable for reading the pushbutton status
- int i;
- int j;
- buttonState = digitalRead(buttonPin);
- // check if the pushbutton is pressed.
- // if it is, the buttonState is HIGH:
- if (buttonState == HIGH) {
- digitalWrite(dirpin, LOW); // Set the direction.
- for(i=0; i<90; i++){
- if(direction == 0){
- for (j = 0; j<30; j++) // Iterate for 4000 microsteps.
- {
- digitalWrite(dirpin, LOW);
- digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
- digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
- delayMicroseconds(500); // This delay time is close to top speed for this
- }
- for (j = 0; j<50; j++) // Iterate for 4000 microsteps.
- {
- digitalWrite(dirpin, HIGH);
- digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
- digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
- delayMicroseconds(500); // This delay time is close to top speed for this
- }
- }
- if(direction == 1){
- for (j = 0; j<30; j++) // Iterate for 4000 microsteps.
- {
- digitalWrite(dirpin, HIGH);
- digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
- digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
- delayMicroseconds(500); // This delay time is close to top speed for this
- }
- for (j = 0; j<50; j++) // Iterate for 4000 microsteps.
- {
- digitalWrite(dirpin, LOW);
- digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
- digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
- delayMicroseconds(500); // This delay time is close to top speed for this
- }
- }
- }
- if(direction==0){
- direction = 1;
- }else{
- direction = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement