Is this the proper way to do analog reads of all sensors one by one with this library? I'm using a teensy 4.
Or do I have to keep the #define teensy 4 etc?
Code:
#include <ADC.h>
#include <ADC_util.h>
ADC *adc = new ADC(); // adc object
#define PINS 14
#define DIG_PINS 10
#define PINS_DIFF 0
uint8_t adc_pins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13};
uint8_t adc_pins_dig[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
uint8_t adc_pins_diff[] = {};
void setup()
{
Serial.begin(9600);
///// ADC0 ////
adc->adc0->setAveraging(1); // set number of averages
adc->adc0->setResolution(10); // set bits of resolution
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED); // change the conversion speed
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED); // change the sampling speed
////// ADC1 /////
adc->adc1->setAveraging(1); // set number of averages
adc->adc1->setResolution(10); // set bits of resolution
adc->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED); // change the conversion speed
adc->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED); // change the sampling speed
delay(500);
}
void loop()
{
uint32_t sensorValue[10];
for (int i = 0; i < PINS; i++)
{
sensorValue[i] = adc->analogRead(adc_pins[i]);
}
}
Can I remove the digital pins from the code since I'm not using them?
Also what are these:
#define PINS_DIFF 0
uint8_t adc_pins_diff[] = {};
I'm new at coding and trying to learn how to use this library.