forked from hadefuwa/elegoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper_Example.ino
50 lines (37 loc) · 1.19 KB
/
stepper_Example.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
40
41
42
43
44
45
46
47
48
49
50
//www.elegoo.com
//2018.10.25
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
*/
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 17; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
void setup() {
myStepper.setSpeed(rolePerMinute);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
char inputVariable = Serial.read();
if (inputVariable == 'o')
{
// step one revolution in one direction:
Serial.println("Opening..");
myStepper.step(stepsPerRevolution);
delay(500);
Serial.println("Open.");
}
if (inputVariable == 'c')
{
Serial.println("Closing..");
myStepper.step(-stepsPerRevolution);
delay(500);
Serial.println("Closed.");
}
}