Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Simple Stepper Motor Control Exaple Code
- *
- * by Dejan Nedelkovski, www.HowToMechatronics.com
- *
- */
- // defines pins numbers
- const int stepPin = 3;
- const int dirPin = 4;
- int snelheid = 2000;//hoe groter hoe trager
- int stappen = 200;
- void setup() {
- // Sets the two pins as Outputs
- pinMode(stepPin,OUTPUT);
- pinMode(dirPin,OUTPUT);
- }
- void loop() {
- digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
- // Makes 200 pulses for making one full cycle rotation
- for(int x = 0; x < stappen; x++) {
- digitalWrite(stepPin,HIGH);
- delayMicroseconds(snelheid);
- digitalWrite(stepPin,LOW);
- delayMicroseconds(snelheid);
- }
- delay(300); // One second delay
- digitalWrite(dirPin,LOW); //Changes the rotations direction
- // Makes 400 pulses for making two full cycle rotation
- for(int x = 0; x < stappen; x++) {
- digitalWrite(stepPin,HIGH);
- delayMicroseconds(snelheid);
- digitalWrite(stepPin,LOW);
- delayMicroseconds(snelheid);
- }
- delay(300);
- }
Advertisement
Add Comment
Please, Sign In to add comment