-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsteppers.ino
65 lines (52 loc) · 1.24 KB
/
steppers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const int dir = 3; //pins to go to motor driver
const int stepp = 4;
int microseconds_delay;
char input;
boolean newData = false;
void setup() {
//set pins as outputs
pinMode(stepp,OUTPUT);
pinMode(dir,OUTPUT);
//set direction pin high to choose direction
digitalWrite(dir,HIGH);
//begin serial connection
Serial.begin(9600);
//set initial speed
microseconds_delay = 1000;
}
void loop() {
//get input data and update variables
recvOneChar();
showNewData();
//continually send steps to step pin on arduino
digitalWrite(stepp,HIGH);
delayMicroseconds(microseconds_delay);
digitalWrite(stepp,LOW);
delayMicroseconds(microseconds_delay);
}
//take in one char of data at a time
void recvOneChar() {
if (Serial.available() > 0) {
input = Serial.read();
newData = true;
}
}
//for each received char print it back to serial and set step period
void showNewData() {
if (newData == true) {
Serial.print(input);
if(input == 49){
microseconds_delay = 500;
}
if(input == 50){
microseconds_delay = 1000;
}
if(input == 51){
microseconds_delay = 1500;
}
if(input == 52){
microseconds_delay = 2000;
}
newData = false;
}
}