-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
106 lines (86 loc) · 2.86 KB
/
main.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// enable
#define enable 8
// 1° driver
#define xDir 5
#define xStep 2
// 2° driver
#define yDir 6
#define yStep 3
// 3° driver
#define zDir 7
#define zStep 4
// botoes
#define bUP 12
#define bDOWN 13
// sensores de final de curso/top and bottom travel limit sensors
#define sensorFinalDeCursoTop 11
#define sensorFinalDeCursoBottom 10
int stepsX = 1600;// num de voltas/turns
int stepDelay = 300; //velocidade/speed
void setup(){
pinMode(xDir, OUTPUT); pinMode(xStep, OUTPUT);// 1° driver
pinMode(yDir, OUTPUT); pinMode(yStep, OUTPUT);// 2° driver
pinMode(zDir, OUTPUT); pinMode(zStep, OUTPUT);// 3° driver
pinMode(bUP, INPUT_PULLUP); pinMode(bDOWN, INPUT_PULLUP);//botoes/buttons
pinMode(sensorFinalDeCursoTop, INPUT_PULLUP);//sensor de final de curso top
pinMode(sensorFinalDeCursoBottom, INPUT_PULLUP);//sensor de final de curso bottom
pinMode(enable, OUTPUT);
digitalWrite(enable,LOW);
Serial.begin(9600);
}
void loop(){
int varUP = digitalRead(bUP);
int varDOWN = digitalRead(bDOWN);
int varTop = digitalRead(sensorFinalDeCursoTop);
int varBottom = digitalRead(sensorFinalDeCursoBottom);
delay(50);
if(varUP == LOW && varTop != LOW){
digitalWrite(xDir, LOW);//direçao sentido horario/CW rotation
digitalWrite(yDir, LOW);//direçao sentido horario/CW rotation
digitalWrite(zDir, LOW);//direçao sentido horario/CW rotation
for(int i = 0; i < stepsX; i++){
varTop = digitalRead(sensorFinalDeCursoTop);
if(varTop == LOW){
Serial.println("top");
break;
}
digitalWrite(xStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(xStep, LOW);
delayMicroseconds(stepDelay);
digitalWrite(yStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(yStep, LOW);
delayMicroseconds(stepDelay);
digitalWrite(zStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(zStep, LOW);
delayMicroseconds(stepDelay);
}
}else if(varDOWN == LOW && varBottom != LOW){
digitalWrite(xDir, HIGH);//direçao sentido anti horario/CCW rotation
digitalWrite(yDir, HIGH);//direçao sentido anti horario/CCW rotation
digitalWrite(zDir, HIGH);//direçao sentido anti horario/CCW rotation
for(int i = 0; i < stepsX; i++){
varBottom = digitalRead(sensorFinalDeCursoBottom);
if(varBottom == LOW){
Serial.println("bottom");
break;
}
digitalWrite(xStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(xStep, LOW);
delayMicroseconds(stepDelay);
digitalWrite(yStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(yStep, LOW);
delayMicroseconds(stepDelay);
digitalWrite(zStep, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(zStep, LOW);
delayMicroseconds(stepDelay);
}
}else{
Serial.println("idle");
}
}