-
Notifications
You must be signed in to change notification settings - Fork 0
/
rangefinder.ino
64 lines (48 loc) · 1.19 KB
/
rangefinder.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
#define Range1a 2
#define Range1b 3
#define Range2a 5
#define Range2b 6
#define Range3a 8
#define Range3b 9
#define Range4a 11
#define Range4b 12
// One time setup for range finding
void setup() {
pinMode(Range1a, INPUT);
pinMode(Range1b, OUTPUT);
pinMode(Range2a, INPUT);
pinMode(Range2b, OUTPUT);
pinMode(Range3a, INPUT);
pinMode(Range3b, OUTPUT);
pinMode(Range4a, INPUT);
pinMode(Range4b, OUTPUT);
delay(250);
digitalWrite(Range1b, LOW);
digitalWrite(Range2b, LOW);
digitalWrite(Range3b, LOW);
digitalWrite(Range4b, LOW);
Serial.begin(9600);
}
void loop() {
delay(1000);
digitalWrite(Range1b, HIGH);
long pulse = pulseIn(Range1a, HIGH);
digitalWrite(Range1b, LOW);
long inches = pulse/127;
Serial.println(inches);
digitalWrite(Range2b, HIGH);
pulseIn(Range2a, HIGH);
digitalWrite(Range2b, LOW);
inches = pulse/147;
Serial.println(inches);
digitalWrite(Range3b, HIGH);
pulseIn(Range3a, HIGH);
digitalWrite(Range3b, LOW);
inches = pulse/147;
Serial.println(inches);
digitalWrite(Range4b, HIGH);
pulseIn(Range4a, HIGH);
digitalWrite(Range4b, LOW);
inches = pulse/147;
Serial.println(inches);
}