forked from maiafacens/maia_robotJr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaia Jr Challenge
65 lines (65 loc) · 1.47 KB
/
Maia Jr Challenge
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
//novo codigo Maia Jr
// C++ code
//
int Ultrasonic = 0;
int UltrasonicD = 0;
int UltrasonicE = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup()
{
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop()
{
Ultrasonic = 0.01723 * readUltrasonicDistance(13, 2);
UltrasonicD = 0.01723 * readUltrasonicDistance(10, 11);
UltrasonicE = 0.01723 * readUltrasonicDistance(12, 9);
if (Ultrasonic <= 10) {
// M. DIREITA
analogWrite(3, 100);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
// M. ESQUERDA
analogWrite(6, 100);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
delay(700); // Espera 700 millisegundos
Serial.println(Ultrasonic);
}
if (UltrasonicD <= 15){
// M. DIREITA
analogWrite(3, 100);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
// M. ESQUERDA
analogWriete (6, 100);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
if (UltrasonicE <= 15){
// M. DIREITO
analogWrite(3, 100);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
// M. ESQUERDA
analogWrite(6, 100);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
}
}