Arduino + Easy Driver + CDROM Stepper motor




Arduino Sketch



#define stp 2
#define dir 3

//Declare variables for functions
char user_input;
int x;
int y;
int state;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
 
  digitalWrite(stp, LOW);
  digitalWrite(dir, LOW);
 
}

//Main loop
void loop() {
 
 
    //Read direction pin state and change it
    state=digitalRead(dir);
    if(state == HIGH)
    {
      digitalWrite(dir, LOW);
    }
    else if(state ==LOW)
    {
      digitalWrite(dir,HIGH);
    }
   
    for(y=1; y<500; y++)
    {
      digitalWrite(stp,HIGH); //Trigger one step
      delay(1);
      digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again
      delay(1);
    }
 
   
}

ความคิดเห็น