Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----( Import needed libraries )-----*/
- #include <AccelStepper.h>
- /*-----( Declare Constants and Pin Numbers )-----*/
- #define FULLSTEP 4
- #define HALFSTEP 8
- // motor pins
- #define motorPin1 4 // Blue - 28BYJ48 pin 1
- #define motorPin2 5 // Pink - 28BYJ48 pin 2
- #define motorPin3 6 // Yellow - 28BYJ48 pin 3
- #define motorPin4 7 // Orange - 28BYJ48 pin 4
- // Red - 28BYJ48 pin 5 (VCC)
- #define motorPin5 8 // Blue - 28BYJ48 pin 1
- #define motorPin6 9 // Pink - 28BYJ48 pin 2
- #define motorPin7 10 // Yellow - 28BYJ48 pin 3
- #define motorPin8 11 // Orange - 28BYJ48 pin 4
- // Red - 28BYJ48 pin 5 (VCC)
- /*-----( Declare objects )-----*/
- // NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
- AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
- AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
- void setup() /****** SETUP: RUNS ONCE ******/
- {
- stepper1.setMaxSpeed(1000.0);
- stepper1.setAcceleration(50.0);
- stepper1.setSpeed(200);
- stepper1.moveTo(4048); // 2048 = 1 revolution
- stepper2.setMaxSpeed(1000.0);
- stepper2.setAcceleration(50.0);
- stepper2.setSpeed(200);
- stepper2.moveTo(-2448); // 2048 = 1 revolution minus 400 to make it asymetric asymetric
- }//--(end setup )---
- void loop() /****** LOOP: RUNS CONSTANTLY ******/
- {
- //Change direction at the limits
- if (stepper1.distanceToGo() == 0)
- stepper1.moveTo(-stepper1.currentPosition());
- if (stepper2.distanceToGo() == 0)
- stepper2.moveTo(-stepper2.currentPosition());
- stepper1.run();
- stepper2.run();
- }//--(end main loop )---
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement