-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from arduino-libraries/dac_loop_mode
AdvancedDAC: Add support for loop mode.
- Loading branch information
Showing
4 changed files
with
61 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This examples shows how to use the DAC in loop mode. In loop mode the | ||
// DAC starts automatically after all buffers are filled, and continuously | ||
// cycle through over all buffers. | ||
#include <Arduino_AdvancedAnalog.h> | ||
|
||
AdvancedDAC dac1(A12); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
while (!Serial) { | ||
|
||
} | ||
|
||
// Start DAC in loop mode. | ||
if (!dac1.begin(AN_RESOLUTION_12, 16000, 32, 16, true)) { | ||
Serial.println("Failed to start DAC1 !"); | ||
while (1); | ||
} | ||
|
||
// Write all buffers. | ||
uint16_t sample = 0; | ||
while (dac1.available()) { | ||
// Get a free buffer for writing. | ||
SampleBuffer buf = dac1.dequeue(); | ||
|
||
// Write data to buffer. | ||
for (int i=0; i<buf.size(); i++) { | ||
buf.data()[i] = sample; | ||
} | ||
|
||
// Write the buffer to DAC. | ||
dac1.write(buf); | ||
sample += 256; | ||
} | ||
} | ||
|
||
|
||
void loop() { | ||
// In loop mode, no other DAC functions need to be called. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters