Skip to content

Commit 53ffa5d

Browse files
authored
Allow setting list of pins to sample after construction
Arguably, in user code, the list of pins to sample will typically be known and fixed at compile-time. However, when wrapping this into a library (Mozzi; for the purpose of providing a cross-platform analog read mechanism), it will be very helpful to have a way to adjust the pins to sample after construction.
1 parent 80eeb61 commit 53ffa5d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/AdvancedADC.h

+8
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,18 @@ class AdvancedADC {
4242
adc_pins[n_channels++] = analogPinToPinName(p);
4343
}
4444
}
45+
AdvancedADC(): n_channels(0), descr(nullptr) {}
4546
~AdvancedADC();
4647
bool available();
4748
SampleBuffer read();
4849
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers);
50+
int begin(uint32_t resolution, uint32_t sample_rate, size_t n_samples, size_t n_buffers, size_t n_pins, pin_size_t *pins) {
51+
static_assert(n_pins < AN_MAX_ADC_CHANNELS, "A maximum of 5 channels can be sampled successively.");
52+
for (size_t i = 0; i < n_pins; ++i) {
53+
adc_pins[i] = analogPinToPinName(pins[i]);
54+
}
55+
n_channels = n_pins;
56+
}
4957
int stop();
5058
};
5159

0 commit comments

Comments
 (0)