-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstepper_oneRevolution.ino
40 lines (32 loc) · 1002 Bytes
/
stepper_oneRevolution.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
Stepper Motor - One Revolution
Motor will first turn clockwise one rev, then counterclockwise one rev, and so on
The motor is attached to digital pins 4-7 (in signed magnitude mode of Arduino 2A shield)
| DIR2 | 7 |
| EN2 | 6 |
| EN1 | 5 |
| DIR1 | 4 |
*/
#include <Stepper.h>
#define SPEED 60 //motor speed
const int stepsPerRevolution = 200; // number of steps per revolution (depends on motor)
// initialize the stepper library on pins 4 through 7:
Stepper myStepper(stepsPerRevolution, 4, 6, 5, 7);
void setup() {
myStepper.setSpeed(SPEED); //set the speed
Serial.begin(9600); // initialize the serial port
}
void loop() {
clockwise();
delay(2000);
counterclockwise();
delay(2000);
}
void clockwise(){ // step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
}
void counterclockwise(){ // step one revolution in the other direction
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
}