-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMuca_Raw_Basic.ino
65 lines (51 loc) · 1.55 KB
/
Muca_Raw_Basic.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
#include <Muca.h>
Muca muca;
void setup() {
Serial.begin(115200);
// muca.skipLine(TX, (const short[]) { 1, 2, 3, 4 }, 4);
//muca.skipLine(TX, (const short[]) { 14,15,16,17, 18, 19, 20, 21 }, 8);
// muca.skipLine(RX,(const short[]) {11,12}, 2);
muca.init();
muca.useRawData(true); // If you use the raw data, the interrupt is not working
delay(50);
muca.setGain(2);
}
void loop() {
if (muca.updated()) {
// SendRawString();
SendRawByte(); // Faster
}
delay(16); // waiting 16ms for 60fps
}
void SendRawString() {
// Print the array value
for (int i = 0; i < NUM_TX * NUM_RX; i++) {
if (muca.grid[i] >= 0) Serial.print(muca.grid[i]); // The +30 is to be sure it's positive
if (i != NUM_TX * NUM_RX - 1)
Serial.print(",");
}
Serial.println();
}
void SendRawByte() {
// The array is composed of 254 bytes. The two first for the minimum, the 252 others for the values.
// HIGH byte minimum | LOW byte minimum | value 1
unsigned int minimum = 80000;
uint8_t rawByteValues[254];
for (int i = 0; i < NUM_TX * NUM_RX; i++) {
if (muca.grid[i] > 0 && minimum > muca.grid[i]) {
minimum = muca.grid[i]; // The +30 is to be sure it's positive
}
}
rawByteValues[0] = highByte(minimum);
rawByteValues[1] = lowByte(minimum);
for (int i = 0; i < NUM_TX * NUM_RX; i++) {
rawByteValues[i + 2] = muca.grid[i] - minimum;
// Serial.print(rawByteValues[i+2]);
// Serial.print(",");
}
// Serial.println();
//GetFPS();
Serial.write(rawByteValues, 254);
Serial.flush();
//Serial.println();
}