Creates an object associated to a specific pin.
AdvancedADC adc(analogPin);
- Pin
A0
throughA11
can be associated.
Nothing.
Initializes the ADC with the specific parameters. The begin()
method is firstly used to initialize the library.
If reconfigured during program execution, use stop()
first.
adc0.begin(resolution, sample_rate, n_samples, n_buffers)
enum
- analog read resolution (choose from 8, 10, 12, 14, 16 bit).AN_RESOLUTION_8
AN_RESOLUTION_10
AN_RESOLUTION_12
AN_RESOLUTION_14
AN_RESOLUTION_16
int
- sample_rate - the sample rate / frequency in Hertz, e.g.16000
.int
- n_samples - number of samples we want to acquire, e.g.32
. When reading the ADC, we store these samples into a specific buffer (see SampleBuffer), and read them viabuffer[x]
, wherex
is the sample you want to retrieve.int
- n_buffers - the number of buffers in the queue.
1 on success, 0 on failure.
Bool to check if there's any available data on the ADC channel.
if(adc0.available()){}
None.
1 on success, 0 on failure.
Reads the first available byte in the buffer.
Stops the ADC and buffer transfer, and releases any memory allocated for the buffer array.
adc.stop()
1
Creates a DAC object on a specific pin.
AdvancedDAC dac0(A12);
AdvancedDAC dac1(A13);
A12
orA13
(DAC0 or DAC1 channels).
Nothing.
Initializes the DAC with the specific parameters. The begin()
method is firstly used to initialize the library.
If reconfigured during program execution, use stop()
first.
dac0.begin(resolution, frequency, n_samples, n_buffers)
enum
- resolution (choose from 8, 10, 12 bit)AN_RESOLUTION_8
AN_RESOLUTION_10
AN_RESOLUTION_12
int
- frequency - the frequency in Hertz, e.g.8000
.int
- n_samples - number of samples we want to write, e.g.32
. When writing to the DAC, we first write the samples into a buffer (see SampleBuffer), and write it to the DAC usingdac_out.write(buf)
.int
- n_buffers - the number of buffers in the queue.
1 on success, 0 on failure.
Checks if the DAC channel is available to write to.
if(dac0.available()){}
None.
1 on success, 0 on failure.
Creates a buffer object and waits until a buffer to become available.
SampleBuffer buf = dac.dequeue();
for (size_t i=0; i<buf.size(); i++) {
buf[i] = SAMPLES_BUFFER[i];
}
dac1.write(buf);
Writes the buffer to the DAC channel specified. Before writing, the cached data is flushed.
dac1.write(buf);
- A buffer containing the samples (see SampleBuffer).
Stops the DAC timer and buffer transfer, and releases any memory allocated for the buffer array.
dac.stop()
1
Sets the frequency for the DAC. This can only be used after begin()
, where an initial frequency is set.
int frequency = 20000;
dac.frequency(frequency);
int
- frequency in Hertz (Hz).
Sample
is the data type used for the SampleBuffer
, and is identical to an unsigned short variable (uint16_t
).
A single Sample
can store 2^16 or 65,535 distinct values.
SampleBuffer
is used to store samples (see Sample) that are then written to the DAC. Before writing, first use dequeue()
, then write data to the buffer.
SampleBuffer buf = dac.dequeue();
for (size_t i=0; i<buf.size(); i++) {
buf[i] = SAMPLES_BUFFER[i];
}
dac1.write(buf);
Returns a pointer to the buffer's memory.
buf.data()
Returns the size of the buffer.
buf.size()
Returns the total number of bytes used to store the audio data, by using the formula n_samples * n_channels * sample
.
buf.bytes()
- Total number of bytes.
Clears the data cache.
buf.flush()
Invalidats the cache by discarding the data.
buf.invalidate()
Returns the timestamp of the buffer.
buf.timestamp()
- Timestamp as
int
.
Returns the number of channels used in the buffer.
buf.channels()
- Timestamp as
int
.
Releases the buffer back into a free pool.
buf.release()
- Nothing (void).
Sets flag(s) for the buffer.
buf.setflags(int arg)
Get flag(s) of the buffer.
buf.getflags(int arg)
int
- flags.
Clear flag(s) from the buffer.
buf.getflags(int arg)
Returns the amount of writable elements in the buffer.
buf.writable()
- Amount of readable elements in the buffer.
Returns the amount of readable elements in the buffer.
buf.readable()
Used to obtain a buffer from the free queue.
buf.allocate()
Releases the buffer back to the free queue.
buf.release()
Add a DMA buffer to the ready queue.
buf.enqueue()
Return a DMA buffer from the ready queue.
buf.dequeue()