-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDAC_Two_Channels.ino
44 lines (33 loc) · 971 Bytes
/
DAC_Two_Channels.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
// This example outputs an 8KHz square wave on A12/DAC0 and 16KHz square wave on ADC13/DAC1.
#include <Arduino_AdvancedAnalog.h>
AdvancedDAC dac1(A12);
AdvancedDAC dac2(A13);
void setup() {
Serial.begin(9600);
while (!Serial) {
}
if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) {
Serial.println("Failed to start DAC1 !");
while (1);
}
if (!dac2.begin(AN_RESOLUTION_12, 16000, 32, 64)) {
Serial.println("Failed to start DAC2 !");
while (1);
}
}
void dac_output_sq(AdvancedDAC &dac_out) {
if (dac_out.available()) {
// Get a free buffer for writing.
SampleBuffer buf = dac_out.dequeue();
// Write data to buffer.
for (int i=0; i<buf.size(); i++) {
buf.data()[i] = (i % 2 == 0) ? 0: 0xfff;
}
// Writethe buffer to DAC.
dac_out.write(buf);
}
}
void loop() {
dac_output_sq(dac1);
dac_output_sq(dac2);
}