Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.16 KB | None | 0 0
  1. int dirpin = 5;
  2. int steppin = 3;
  3. int buttonPin = 2;     // the number of the pushbutton pin
  4. int direction = LOW;
  5.  
  6.  
  7. void setup() {
  8.   pinMode(dirpin, OUTPUT);
  9.   pinMode(steppin, OUTPUT);
  10.   pinMode(buttonPin, INPUT);  
  11. }
  12.  
  13.  
  14. void loop(){
  15.   int buttonState = 0;         // variable for reading the pushbutton status
  16.   int i;
  17.   int j;
  18.  
  19.   buttonState = digitalRead(buttonPin);
  20.  
  21.   // check if the pushbutton is pressed.
  22.   // if it is, the buttonState is HIGH:
  23.   if (buttonState == HIGH) {    
  24.     digitalWrite(dirpin, LOW);     // Set the direction.
  25.  
  26. for(i=0; i<90; i++){
  27.   if(direction == 0){
  28.   for (j = 0; j<30; j++)       // Iterate for 4000 microsteps.
  29.   {
  30.     digitalWrite(dirpin, LOW);
  31.     digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
  32.     digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
  33.     delayMicroseconds(500);      // This delay time is close to top speed for this
  34.   }
  35.     for (j = 0; j<50; j++)       // Iterate for 4000 microsteps.
  36.   {
  37.     digitalWrite(dirpin, HIGH);
  38.     digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
  39.     digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
  40.     delayMicroseconds(500);      // This delay time is close to top speed for this
  41.   }
  42.  
  43.   }
  44.   if(direction == 1){
  45.     for (j = 0; j<30; j++)       // Iterate for 4000 microsteps.
  46.   {
  47.     digitalWrite(dirpin, HIGH);
  48.     digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
  49.     digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
  50.     delayMicroseconds(500);      // This delay time is close to top speed for this
  51.   }
  52.     for (j = 0; j<50; j++)       // Iterate for 4000 microsteps.
  53.   {
  54.     digitalWrite(dirpin, LOW);
  55.     digitalWrite(steppin, LOW);  // This LOW to HIGH change is what creates the
  56.     digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
  57.     delayMicroseconds(500);      // This delay time is close to top speed for this
  58.   }
  59.   }
  60.  
  61.  
  62.  
  63. }
  64.   if(direction==0){
  65.     direction = 1;
  66.   }else{
  67.     direction = 0;
  68.   }
  69.  
  70.   }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement