]> git.piffa.net Git - sketchbook_andrea/blob - motors/stepper/step_4_phase_ardino_library/step_4_phase_ardino_library.ino
a2ab28e423a415e1780c1113320169395ce2def2
[sketchbook_andrea] / motors / stepper / step_4_phase_ardino_library / step_4_phase_ardino_library.ino
1 /* YourDuino.com Example Software Sketch
2    Small Stepper Motor and Driver V1.3 11/30/2013
3    http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
4    Shows 4-step sequence, Then 1/2 turn and back different speeds
5    terry@yourduino.com */
6
7 /*-----( Import needed libraries )-----*/
8 #include <Stepper.h>
9
10 /*-----( Declare Constants, Pin Numbers )-----*/
11 //---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
12 #define STEPS_PER_MOTOR_REVOLUTION 32   
13
14 //---( Steps per OUTPUT SHAFT of gear reduction )---
15 #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048  
16
17 /*-----( Declare objects )-----*/
18 // create an instance of the stepper class, specifying
19 // the number of steps of the motor and the pins it's
20 // attached to
21
22 //The pin connections need to be 4 pins connected
23 // to Motor Driver In1, In2, In3, In4  and then the pins entered
24 // here in the sequence 1-3-2-4 for proper sequencing
25 Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
26
27
28 /*-----( Declare Variables )-----*/
29 int  Steps2Take;
30
31 void setup()   /*----( SETUP: RUNS ONCE )----*/
32 {
33 // Nothing  (Stepper Library sets pins as outputs)
34 }/*--(end setup )---*/
35
36 void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
37 {
38   small_stepper.setSpeed(1);   // SLOWLY Show the 4 step sequence 
39   Steps2Take  =  4;  // Rotate CW
40   small_stepper.step(Steps2Take);
41   delay(2000);
42
43   Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CW 1/2 turn
44   small_stepper.setSpeed(100);   
45   small_stepper.step(Steps2Take);
46   delay(1000);
47   
48   Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CCW 1/2 turn  
49   small_stepper.setSpeed(700);  // 700 a good max speed??
50   small_stepper.step(Steps2Take);
51   delay(2000);
52
53 }/* --(end main loop )-- */
54
55 /* ( THE END ) */
56