-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ino
64 lines (58 loc) · 1.35 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
#include <Servo.h>
volatile long A;
float checkdistance() {
digitalWrite(11, LOW);
delayMicroseconds(2);
digitalWrite(11, HIGH);
delayMicroseconds(10);
digitalWrite(11, LOW);
float distance = pulseIn(10, HIGH) / 58.00;
delay(10);
return distance;
}
Servo servo_3;
Servo servo_6;
Servo servo_9;
void setup() {
A = 0;
pinMode(11, OUTPUT);
pinMode(10, INPUT);
pinMode(12, OUTPUT);
servo_3.attach(3);
servo_6.attach(6);
servo_9.attach(9);
}
void loop() {
if (checkdistance() < 20) {
A = random(0, 4);
switch (A) {
case 1:
tone(12, 131);
delay(100);
noTone(12);
servo_3.write(179);
delay(1000);
servo_3.write(90);
delay(500);
break;
case 2:
tone(12, 131);
delay(100);
noTone(12);
servo_6.write(179);
delay(1000);
servo_6.write(90);
delay(500);
break;
case 3:
tone(12, 131);
delay(100);
noTone(12);
servo_9.write(179);
delay(1000);
servo_9.write(90);
delay(500);
break;
}
}
}