Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. // defines pins numbers
  2. const int stepPin = 5;
  3. const int dirPin = 2;
  4. const int enPin = 8;
  5. void setup() {
  6.  
  7. // Sets the two pins as Outputs
  8. pinMode(stepPin,OUTPUT);
  9. pinMode(dirPin,OUTPUT);
  10.  
  11. pinMode(enPin,OUTPUT);
  12. digitalWrite(enPin,LOW);
  13.  
  14. }
  15. void loop() {
  16.  
  17. digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
  18. // Makes 200 pulses for making one full cycle rotation
  19. for(int x = 0; x < 800; x++) {
  20. digitalWrite(stepPin,HIGH);
  21. delayMicroseconds(500);
  22. digitalWrite(stepPin,LOW);
  23. delayMicroseconds(500);
  24. }
  25. delay(1000); // One second delay
  26.  
  27. digitalWrite(dirPin,LOW); //Changes the rotations direction
  28. // Makes 400 pulses for making two full cycle rotation
  29. for(int x = 0; x < 800; x++) {
  30. digitalWrite(stepPin,HIGH);
  31. delayMicroseconds(500);
  32. digitalWrite(stepPin,LOW);
  33. delayMicroseconds(500);
  34. }
  35. delay(1000);
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement