]> git.piffa.net Git - sketchbook_andrea/blob - motors/stepper/stepper_6_acceleration/stepper_6_acceleration.ino
step motors
[sketchbook_andrea] / motors / stepper / stepper_6_acceleration / stepper_6_acceleration.ino
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
11
12  - V1.01 11/30/2013
13    Questions: terry@yourduino.com */
14
15 /*-----( Import needed libraries )-----*/
16 #include <AccelStepper.h>
17 /*-----( Declare Constants and Pin Numbers )-----*/
18 #define FULLSTEP 4
19 #define HALFSTEP 8
20 // motor pins
21
22                         
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
30
31 AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
32
33 /*-----( Declare Variables )-----*/
34 //none
35
36 void setup()   /****** SETUP: RUNS ONCE ******/
37 {  
38   stepper2.setMaxSpeed(1000.0);
39   stepper2.setAcceleration(50.0);
40   stepper2.setSpeed(200);
41   stepper2.moveTo(-2048);  // 1 revolution 
42
43 }//--(end setup )---
44
45
46 void loop()   /****** LOOP: RUNS CONSTANTLY ******/
47 {
48   //Change direction at the limits
49     if (stepper2.distanceToGo() == 0) 
50     stepper2.moveTo(-stepper2.currentPosition());
51   
52   stepper2.run();
53
54 }//--(end main loop )---
55
56 /*-----( Declare User-written Functions )-----*/
57 //none
58 //*********( THE END )***********