]> git.piffa.net Git - sketchbook_andrea/blob - motors/stepper/stepper_oneRevolution_adapted/stepper_oneRevolution_adapted.ino
7c40cebaa2edfa7e839dfa51b944d26507f1abba
[sketchbook_andrea] / motors / stepper / stepper_oneRevolution_adapted / stepper_oneRevolution_adapted.ino
1
2 /* 
3  Stepper Motor Control - one revolution
4  
5  Revisionato per i motori 5v 28YBJ-48 con controller board
6  - http://arduino-info.wikispaces.com/SmallSteppers
7  
8  This program drives a unipolar or bipolar stepper motor. 
9  The motor is attached to digital pins 8 - 11 of the Arduino.
10  
11  The motor should revolve one revolution in one direction, then
12  one revolution in the other direction.  
13  
14   
15  Created 11 Mar. 2007
16  Modified 30 Nov. 2009
17  by Tom Igoe
18  
19  */
20
21 #include <Stepper.h>
22
23 const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
24 // for your motor
25 //  2048 = 360deg = 32*64 in 4-step sequence as in Step Library
26 //  1025 = 180deg
27 //  512.5 = 90deg
28 //  5.6944 = 1deg
29
30 // initialize the stepper library on pins 8 through 11:
31 Stepper myStepper(stepsPerRevolution,8,10,9,11); 
32 // Sequence is 1-3-2-4
33 // Valid values:  (8,10,11,9), (9,11,8,10), (10,8,9,11), and (11,9,10,8)
34 // 1N1 on pin 8
35 // 1N2 on pin 9
36 // 1N3 on pin 10
37 // 1N4 on pin 11
38 // powered via 5v
39 // Max speed is 14RPM @ 5v
40
41 void setup() {
42   // set the speed at 60 rpm:
43   myStepper.setSpeed(14); // Max speed is 14RPM @5v
44   // initialize the serial port:
45   Serial.begin(9600);
46 }
47
48 void loop() {
49   // step one revolution  in one direction:
50    Serial.println("clockwise");
51   myStepper.step(stepsPerRevolution);
52   delay(500);
53   
54    // step one revolution in the other direction:
55   Serial.println("counterclockwise");
56   myStepper.step(-stepsPerRevolution);
57   delay(500); 
58 }
59