-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathStack.ino
More file actions
27 lines (24 loc) · 607 Bytes
/
Stack.ino
File metadata and controls
27 lines (24 loc) · 607 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
#include <CircularBuffer.hpp>
CircularBuffer<unsigned int, 100> stack;
#define SAMPLE_PIN A0
void setup() {
Serial.begin(9600);
pinMode(SAMPLE_PIN, INPUT);
}
// stacks up pin analog readings then printing in reverse order when maxed
void loop() {
unsigned int sample = analogRead(SAMPLE_PIN);
if (sample != stack.last()) {
stack.push(sample);
}
if (stack.isFull()) {
Serial.println("Stack is full:");
while (!stack.isEmpty()) {
Serial.print(" # ");
Serial.println(stack.pop());
}
// the following is unnecessary, still here to demonstrate its use
stack.clear();
}
delay(50);
}