v12345vtm

test stepper

Jul 14th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /* Simple Stepper Motor Control Exaple Code
  2. *
  3. * by Dejan Nedelkovski, www.HowToMechatronics.com
  4. *
  5. */
  6.  
  7. // defines pins numbers
  8. const int stepPin = 3;
  9. const int dirPin = 4;
  10. int snelheid = 2000;//hoe groter hoe trager
  11. int stappen = 200;
  12.  
  13. void setup() {
  14. // Sets the two pins as Outputs
  15. pinMode(stepPin,OUTPUT);
  16. pinMode(dirPin,OUTPUT);
  17. }
  18. void loop() {
  19. digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  20. // Makes 200 pulses for making one full cycle rotation
  21. for(int x = 0; x < stappen; x++) {
  22. digitalWrite(stepPin,HIGH);
  23. delayMicroseconds(snelheid);
  24. digitalWrite(stepPin,LOW);
  25. delayMicroseconds(snelheid);
  26. }
  27. delay(300); // One second delay
  28.  
  29. digitalWrite(dirPin,LOW); //Changes the rotations direction
  30. // Makes 400 pulses for making two full cycle rotation
  31. for(int x = 0; x < stappen; x++) {
  32. digitalWrite(stepPin,HIGH);
  33. delayMicroseconds(snelheid);
  34. digitalWrite(stepPin,LOW);
  35. delayMicroseconds(snelheid);
  36. }
  37. delay(300);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment