-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelevator.ino
110 lines (95 loc) · 2.09 KB
/
elevator.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
107
108
109
110
int andar;
int your = 0;
void setup(){
//sensores para ir para algum canto
for (int i = 4; i<=7; i++){ pinMode(i, INPUT_PULLUP); }
//sensores qual q ta
for (int i = 8; i<=11; i++){ pinMode(i, INPUT_PULLUP); }
//LEDS
for (int i = 22; i <= 28; i++){ pinMode(i, OUTPUT); }
//motor
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
Serial.begin(9600);
}
void getAndar(){
// pega qual ta
if(digitalRead(4) == LOW){ andar = 4; }
else if (digitalRead(5) == LOW){ andar = 3; }
else if (digitalRead(6) == LOW){ andar = 2; }
else { andar = 1; }
}
void getYourAndar(){
// pega qual ta
if(digitalRead(8) == LOW){
your = 1;
digitalWrite(22, LOW);
digitalWrite(28, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
digitalWrite(23, HIGH);
digitalWrite(24, HIGH);
}
else if (digitalRead(9) == LOW){
your = 2;
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(28, HIGH);
digitalWrite(26, HIGH);
digitalWrite(25, HIGH);
digitalWrite(24, LOW);
digitalWrite(27, LOW);
}
else if (digitalRead(10) == LOW){
your = 3;
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(28, HIGH);
digitalWrite(24, HIGH);
digitalWrite(25, HIGH);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
}
else if (digitalRead(11) == LOW) {
your = 4;
digitalWrite(23, HIGH);
digitalWrite(24, HIGH);
digitalWrite(28, HIGH);
digitalWrite(27, HIGH);
digitalWrite(22, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
}
else {
your = 0;
digitalWrite(22, LOW);
digitalWrite(28, LOW);
digitalWrite(25, LOW);
digitalWrite(26, LOW);
digitalWrite(27, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
}
}
void move(){
if(your < andar){
digitalWrite(3, HIGH);
}else{
digitalWrite(2, HIGH);
}
}
void goNext(){
while(andar != your){
move();
getAndar();
}
}
void loop()
{
getAndar();
getYourAndar();
Serial.print("qual ta --> ");
Serial.println(andar);
if(your != 0){ goNext(); }
}