Skip to content

Commit

Permalink
Examples: Add dual ADC mode example.
Browse files Browse the repository at this point in the history
  • Loading branch information
iabdalkader committed Mar 20, 2024
1 parent 54a69c5 commit 0b6f3fb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/Advanced/ADC_Dual_Mode/ADC_Dual_Mode.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <Arduino_AdvancedAnalog.h>

AdvancedADC adc1(A0, A1);
AdvancedADC adc2(A2, A3);
AdvancedADCDual adc_dual(adc1, adc2);
uint64_t last_millis = 0;

void setup() {
Serial.begin(9600);
while (!Serial) {
}

// Resolution, sample rate, number of samples per channel, queue depth.
if (!adc_dual.begin(AN_RESOLUTION_16, 16000, 32, 32)) {
Serial.println("Failed to start analog acquisition!");
while (1);
}
}

void loop() {
if (adc1.available()) {
SampleBuffer buf1 = adc1.read();
SampleBuffer buf2 = adc2.read();

// Process the buffer.
if (millis() - last_millis > 1) {
Serial.println(buf1.timestamp()); // Print buffer timestamp
Serial.println(buf1[0]); // Print sample from first channel
Serial.println(buf1[1]); // Print sample from second channel

Serial.println(buf2.timestamp()); // Print buffer timestamp
Serial.println(buf2[0]); // Print sample from first channel
Serial.println(buf2[1]); // Print sample from second channel

last_millis = millis();
}

// Release the buffer to return it to the pool.
buf1.release();
buf2.release();
}
}

0 comments on commit 0b6f3fb

Please sign in to comment.