-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathberxa_controller.ino
More file actions
41 lines (35 loc) · 824 Bytes
/
Copy pathberxa_controller.ino
File metadata and controls
41 lines (35 loc) · 824 Bytes
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
#include "NewPing.h"
#include <Process.h>
#include <Bridge.h>
// In centimeters / micro_secs
#define PIN_TRIG 12
#define PIN_ECHO 13
#define MAX_DISTANCE 1000
NewPing sonar(PIN_TRIG, PIN_ECHO, MAX_DISTANCE);
float distance;
void setup() {
Serial.begin (9600);
Bridge.begin();
}
void print_distance(float distance) {
Serial.print("Distance: ");
if (distance >= 400 || distance <= 2) {
Serial.print(distance);
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
}
void loop() {
Process p;
String line,distanceStr;
distance = sonar.ping_cm();
print_distance(distance);
distanceStr = String(distance);
Serial.print(distanceStr);
line = String("python /root/send_udp_package.py " + distanceStr);
p.runShellCommand(line);
delay(500);
}