-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhoton_HuskyLens.ino
71 lines (59 loc) · 1.44 KB
/
Photon_HuskyLens.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
/*
* Project Photon_HuskyLens
* Description:
* Author:
* Date:
*/
//Serial.read();
#include "Particle.h"
// Constants
const unsigned long SEND_INTERVAL_MS = 2000;
const size_t READ_BUF_SIZE = 64;
// Forward declarations
void processBuffer();
// Global variables
int counter = 0;
unsigned long lastSend = 0;
char readBuf[READ_BUF_SIZE];
size_t readBufOffset = 0;
void setup() {
Serial.begin(9600);
// Serial1 RX is connected to Arduino TX (1)
// Serial2 TX is connected to Arduino RX (0)
// Photon GND is connected to Arduino GND
Serial1.begin(9600);
}
//We don't want to do ANYTHING but receive!
void loop() {
//I think we want to axe this whole IF statement
//if (millis() - lastSend >= SEND_INTERVAL_MS) {
// lastSend = millis();
// Serial1.printlnf("%d", ++counter);
// Serial.printlnf("Sent to Arduiuno: %d", counter);
//}
// Read data from serial
while(Serial1.available()) {
if (readBufOffset < READ_BUF_SIZE) {
char c = Serial1.read();
if (c != '\n') {
// Add character to buffer
readBuf[readBufOffset++] = c;
}
else {
// End of line character found, process line
readBuf[readBufOffset] = 0;
processBuffer();
readBufOffset = 0;
}
}
else {
Serial.println("readBuf overflow, emptying buffer");
readBufOffset = 0;
}
}
}
void processBuffer() {
Serial.printlnf("Received from Arduino: %s", readBuf);
//Particle.publish("distance", readBuf, PRIVATE);
//Particle.publish(readBuf, PRIVATE);
}