-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
Struct.ino
44 lines (38 loc) · 839 Bytes
/
Struct.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
#include <CircularBuffer.hpp>
namespace data {
typedef struct {
unsigned long time;
unsigned int value;
bool flag;
} record;
void print(record r) {
Serial.print(r.time);
Serial.print(" ");
Serial.print(r.value);
Serial.print(" ");
Serial.print(r.flag);
}
}
CircularBuffer<data::record, 10> structs;
#define SAMPLE_PIN A0
void setup() {
Serial.begin(9600);
pinMode(SAMPLE_PIN, INPUT);
Serial.println("STARTING UP");
}
void loop() {
unsigned int sample = analogRead(SAMPLE_PIN);
if (sample != structs.last().value) {
structs.push(data::record{millis(), sample, sample > 512});
Serial.println("---");
delay(50);
}
if (structs.isFull()) {
Serial.println("Stack is full:");
while (!structs.isEmpty()) {
data::print(structs.shift());
Serial.println();
}
Serial.println("START AGAIN");
}
}