-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObstacleDetection.ino
58 lines (47 loc) · 1.21 KB
/
ObstacleDetection.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
#include "Ultrasonic.h"
#define RX 10
#define TX 11
#define BAUD 19200
#define SPEED 343
Ultrasonic ultra(RX,TX,BAUD);
void setup() {
Serial.begin(57600);
Serial.println("Serial started!");
}
void testUART() {
ultra.testUart();
while(ultra.serial.available()) {
Serial.println(ultra.serial.read(), HEX);
}
}
void command1() {
//Serial.println("com1");
ultra.burstAndThreshold(LONG);
uint16_t high = ultra.serial.read();
uint16_t low = ultra.serial.read();
uint16_t timeOfFlight = ((high<<8) + low);
Serial.print(timeOfFlight, HEX);
Serial.print("\t");
double distance = ((double) timeOfFlight) * SPEED/2000;
Serial.println(distance);
uint8_t checksum = ultra.serial.read();
//Serial.println("done");
}
void command5() {
//Serial.println("cmd 5");
ultra.burstAndCapture(LONG);
uint16_t high = ultra.serial.read();
uint16_t low = ultra.serial.read();
uint16_t timeOfFlight = ((high<<8) + low);
//Serial.print(timeOfFlight, HEX);
//Serial.print("\t");
double distance = ((double) timeOfFlight) * SPEED/2000;
Serial.println(distance);
uint8_t checksum = ultra.serial.read();
//Serial.println("cmd 5 end");
}
void loop() {
//testUART();
command5();
delay(50);
}