Skip to content

Commit f530b02

Browse files
committed
examples: Add DAC loop mode example.
Signed-off-by: iabdalkader <[email protected]>
1 parent cb081a5 commit f530b02

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This examples shows how to use the DAC in loop mode. In loop mode the
2+
// DAC starts automatically after all buffers are filled, and continuously
3+
// cycle through over all buffers.
4+
#include <Arduino_AdvancedAnalog.h>
5+
6+
AdvancedDAC dac1(A12);
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
11+
while (!Serial) {
12+
13+
}
14+
15+
// Start DAC in loop mode.
16+
if (!dac1.begin(AN_RESOLUTION_12, 16000, 32, 16, true)) {
17+
Serial.println("Failed to start DAC1 !");
18+
while (1);
19+
}
20+
21+
// Write all buffers.
22+
uint16_t sample = 0;
23+
while (dac1.available()) {
24+
// Get a free buffer for writing.
25+
SampleBuffer buf = dac1.dequeue();
26+
27+
// Write data to buffer.
28+
for (int i=0; i<buf.size(); i++) {
29+
buf.data()[i] = sample;
30+
}
31+
32+
// Write the buffer to DAC.
33+
dac1.write(buf);
34+
sample += 256;
35+
}
36+
}
37+
38+
39+
void loop() {
40+
// In loop mode, no other DAC functions need to be called.
41+
}

0 commit comments

Comments
 (0)