1 /* YourDuinoStarter Example: 2 Stepper Motors
2 - WHAT IT DOES: Runs 2 28BYJ-48 stepper motors with AccelStepper Library
3 - Motors accelerate and decelerate simultaneously in opposite rotations
4 - SEE the comments after "//" on each line below
5 - Derived from example code by Mike McCauley
6 - modified by Celem for single stepper
7 - modified by lowres for two steppers
8 NOTE: This may not run 2 motors from USB.
9 May need separate +5 Supply for motors
10 - CONNECTIONS: See Pin definitions below
13 Questions: terry@yourduino.com */
15 /*-----( Import needed libraries )-----*/
16 #include <AccelStepper.h>
17 /*-----( Declare Constants and Pin Numbers )-----*/
23 #define motorPin5 8 // Blue - 28BYJ48 pin 1
24 #define motorPin6 9 // Pink - 28BYJ48 pin 2
25 #define motorPin7 10 // Yellow - 28BYJ48 pin 3
26 #define motorPin8 11 // Orange - 28BYJ48 pin 4
27 // Red - 28BYJ48 pin 5 (VCC)
28 /*-----( Declare objects )-----*/
29 // NOTE: The sequence 1-3-2-4 is required for proper sequencing of 28BYJ48
31 AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
33 /*-----( Declare Variables )-----*/
36 void setup() /****** SETUP: RUNS ONCE ******/
38 stepper2.setMaxSpeed(1000.0);
39 stepper2.setAcceleration(50.0);
40 stepper2.setSpeed(200);
41 stepper2.moveTo(-2048); // 1 revolution
46 void loop() /****** LOOP: RUNS CONSTANTLY ******/
48 //Change direction at the limits
49 if (stepper2.distanceToGo() == 0)
50 stepper2.moveTo(-stepper2.currentPosition());
54 }//--(end main loop )---
56 /*-----( Declare User-written Functions )-----*/
58 //*********( THE END )***********