-
Notifications
You must be signed in to change notification settings - Fork 1
/
lidar_pixy_move.ino
84 lines (67 loc) · 1.5 KB
/
lidar_pixy_move.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <SPI.h>
#include <Pixy.h>
#include <LIDARLite.h>
#include <Wire.h>
#include <Timer.h>
#define X_CENTER ((PIXY_MAX_X-PIXY_MIN_X)/2)
Pixy pixy;
LIDARLite lidar;
uint16_t blocks;
boolean debug = false;
Timer t;
void no() {
int dif;
blocks = -1;
char buffer[100];
blocks = pixy.getBlocks();
// PIXY STUFF
String dir;
static int i = 0;
int CenterOfBlocks;
if (blocks) {
//Serial.println("Block Count: " + String(blocks));
if (blocks == 1) {
CenterOfBlocks = pixy.blocks[0].x;
} else if (blocks == 2) {
CenterOfBlocks = (pixy.blocks[0].x + pixy.blocks[1].x) / 2;
} else {
CenterOfBlocks = 0;
}
//if (blocks == 1 || blocks == 2) {
dif = X_CENTER - CenterOfBlocks;
if (dif < -5) {
sprintf(buffer, "^%s~%s~%s~", "PIXY", "direction", "right");
Serial.print(buffer);
} else if (dif > 5) {
sprintf(buffer, "^%s~%s~%s~", "PIXY", "direction", "left");
Serial.print(buffer);
} else {
sprintf(buffer, "^%s~%s~%s~", "PIXY", "direction", "straight");
Serial.print(buffer);
}
if (debug) {
Serial.println("");
}
}
//LIDAR STUFF
sprintf(buffer, "^%s~%s~%d~", "LIDAR", "cm", lidar.distance());
Serial.print(buffer);
if (debug) {
Serial.println("");
}
}
void setup() {
Serial.begin(74880);
pixy.init();
if (debug) {
Serial.println("PIXY ONLINE");
}
lidar.begin(0, true);
if (debug) {
Serial.println("LIDAR ONLINE");
}
t.every(20, no);
}
void loop() {
t.update();
}