Skip to content

Commit bb77e3f

Browse files
committed
Examples: Add dual ADC mode example.
1 parent af1ea92 commit bb77e3f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <Arduino_AdvancedAnalog.h>
2+
3+
AdvancedADC adc1(A0, A1);
4+
AdvancedADC adc2(A2, A3);
5+
AdvancedADCDual adc_dual(adc1, adc2);
6+
uint64_t last_millis = 0;
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
while (!Serial) {
11+
}
12+
13+
// Resolution, sample rate, number of samples per channel, queue depth.
14+
int ret = adc_dual.begin(AN_RESOLUTION_16, 16000, 32, 32);
15+
if (ret < 0) {
16+
Serial.print("Failed to start analog acquisition!");
17+
Serial.println(ret);
18+
while (1);
19+
}
20+
}
21+
22+
void loop() {
23+
if (adc1.available()) {
24+
SampleBuffer buf1 = adc1.read();
25+
SampleBuffer buf2 = adc2.read();
26+
27+
// Process the buffer.
28+
if (millis() - last_millis > 1) {
29+
Serial.println(buf1.timestamp()); // Print buffer timestamp
30+
Serial.println(buf1[0]); // Print sample from first channel
31+
Serial.println(buf1[1]); // Print sample from second channel
32+
33+
Serial.println(buf2.timestamp()); // Print buffer timestamp
34+
Serial.println(buf2[0]); // Print sample from first channel
35+
Serial.println(buf2[1]); // Print sample from second channel
36+
37+
last_millis = millis();
38+
}
39+
40+
// Release the buffer to return it to the pool.
41+
buf1.release();
42+
buf2.release();
43+
}
44+
}

0 commit comments

Comments
 (0)