-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlider_Mechanism_New.ino
93 lines (74 loc) · 1.94 KB
/
Slider_Mechanism_New.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
const int IN2=5;
const int IN1=4;
const int PWM=6;
bool upperSen;
bool lowerSen;
String input;
int limitSwitch = 9;
void Motor_Down(int Speed) {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(IN1,HIGH);
digitalWrite(IN2,LOW);
analogWrite(PWM,Speed);
}
void Motor_Up(int Speed) {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);
analogWrite(PWM,Speed);
}
void Motor_Brake(){
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
analogWrite(PWM, 0);
}
void setup() {
pinMode(2 , INPUT);
pinMode(3, INPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(PWM, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(limitSwitch, INPUT);
Serial.begin(115200);
Motor_Brake();
delay(1000);
}
void loop() {
if (Serial.available() > 0) {
input = Serial.readStringUntil('.');
Serial.println(input);
if (input == "DOWN") {
while (digitalRead(2)== HIGH) { //until upperSen is low
Motor_Up(200); delay(10);
}
Motor_Brake();
Serial.println(1);
upperSen = true;
lowerSen = false;
}
if (input == "UP") {
while(digitalRead(3) == HIGH) {//until lowerSen is LOW
Motor_Down(200); delay(10);
}
Motor_Brake();
upperSen = false;
lowerSen = true;
Serial.println(digitalRead(limitSwitch));
if (digitalRead(limitSwitch)==0) {
while (digitalRead(2) == HIGH) {
Motor_Up(200);
}
Motor_Brake();
Serial.println(0);
} else {
Serial.println(1);
}
}
}
}