Advertisement
Guest User

spiral pattern code

a guest
Mar 27th, 2017
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /*-----( Import needed libraries )-----*/
  2. #include <AccelStepper.h>
  3. /*-----( Declare Constants and Pin Numbers )-----*/
  4. #define FULLSTEP 4
  5. #define HALFSTEP 8
  6. // motor pins
  7. #define motorPin1 4 // Blue - 28BYJ48 pin 1
  8. #define motorPin2 5 // Pink - 28BYJ48 pin 2
  9. #define motorPin3 6 // Yellow - 28BYJ48 pin 3
  10. #define motorPin4 7 // Orange - 28BYJ48 pin 4
  11. // Red - 28BYJ48 pin 5 (VCC)
  12. #define motorPin5 8 // Blue - 28BYJ48 pin 1
  13. #define motorPin6 9 // Pink - 28BYJ48 pin 2
  14. #define motorPin7 10 // Yellow - 28BYJ48 pin 3
  15. #define motorPin8 11 // Orange - 28BYJ48 pin 4
  16. // Red - 28BYJ48 pin 5 (VCC)
  17. /*-----( Declare objects )-----*/
  18. // NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
  19. AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
  20. AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
  21.  
  22. void setup() /****** SETUP: RUNS ONCE ******/
  23. {
  24. stepper1.setMaxSpeed(1000.0);
  25. stepper1.setAcceleration(50.0);
  26. stepper1.setSpeed(200);
  27. stepper1.moveTo(4048); // 2048 = 1 revolution
  28. stepper2.setMaxSpeed(1000.0);
  29. stepper2.setAcceleration(50.0);
  30. stepper2.setSpeed(200);
  31. stepper2.moveTo(-2448); // 2048 = 1 revolution minus 400 to make it asymetric asymetric
  32. }//--(end setup )---
  33. void loop() /****** LOOP: RUNS CONSTANTLY ******/
  34. {
  35. //Change direction at the limits
  36. if (stepper1.distanceToGo() == 0)
  37. stepper1.moveTo(-stepper1.currentPosition());
  38. if (stepper2.distanceToGo() == 0)
  39. stepper2.moveTo(-stepper2.currentPosition());
  40. stepper1.run();
  41. stepper2.run();
  42. }//--(end main loop )---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement