// check if gpio is usable as ADC with ADC1
// Macro pour savoir si un canal (obtenu par digitalPinToAnalogChannel) appartient à ADC1
// Sur la majorité des ESP32, ADC1 et ADC2 ont des plages de canaux séparées logiciellement
#define IS_ADC1_CHANNEL(ch) (ch >= 0 && ch < SOC_ADC_MAX_CHANNEL_NUM)
// Macro pour vérifier si un numéro de GPIO appartient à l'ADC1
#define IS_ADC1_GPIO(p) (digitalPinToAnalogChannel(p) != -1 && digitalPinToAnalogChannel(p) < SOC_ADC_MAX_CHANNEL_NUM)
bool Check(int N) {
Serial.println("For gpio n°:" + String(N));
if (SOC_ADC_SUPPORTED) Serial.println("Ok for ADC");
// first get ADC channel, -1 if not ADC compatible
int ch = digitalPinToAnalogChannel(N);
Serial.println("Channel is : " + String(ch));
// second check if channel is for ADC1
if (ch == -1) Serial.println("Not link to ADC unit");
else if (ch < SOC_ADC_MAX_CHANNEL_NUM) Serial.println("ADC unit 1");
else Serial.println("ADC unit 2");
Serial.print("with Macro : it's ");
if (IS_ADC1_GPIO(N)) Serial.println("Ok"); else Serial.println("Not Ok");
Serial.println("**********");
return true;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Check(32);
Check(25);
Check(0);
Check(6);
Check(18);
Check(35);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}