-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduino_stepper_final.ino
78 lines (73 loc) · 1.54 KB
/
arduino_stepper_final.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
66
67
68
69
70
71
72
73
74
75
76
int Distance = 0;
int inByte;
int i;
int a1;
int b;
int a;
int Distance1 = 0;
void vaccum(int dist, int dir)
{
Serial.println("Chamber 2");
for (Distance1 = 0 ; Distance1 < dist ; Distance1++)
{
digitalWrite(8, dir);//2
digitalWrite(9, HIGH);//3
delay(0.01);
digitalWrite(9 , LOW);//3
delay(0.01);
Serial.println(Distance1);
}
}
void setup()
{
// Record the number of steps we've taken void setup() {
pinMode(8, OUTPUT);//direction of roller
pinMode(9, OUTPUT);//step of roller
pinMode(2, OUTPUT);//direction of roller
pinMode(3, OUTPUT);//direction of roller
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
Serial.begin(9600);
}
int code = 0;
int flag = 0;
void loop()
{
int a;
if (flag) {
//Serial.println(code);
if (code == 1)
{
Serial.println("Chamber 1");
for (Distance = 0 ; Distance < 140; Distance++)
{
digitalWrite(9, HIGH);
delay(0.01);
digitalWrite(9, LOW);
delay(0.01);
Serial.println(Distance);
}
} else {
int direct = code % 10;
code = code / 10;
vaccum(code, direct);
code = 0;
}
code = 0;
flag = 0;
}
if (Serial.available() > 0)
{
inByte = Serial.read();
if (inByte != 13 && inByte != 10) {
if (inByte == 92) {
flag = 1;
} else {
int val = inByte - 48;
code = code * 10 + val;
}
}
}
}