|
@@ -187,19 +187,21 @@ void HAL_adc_start_conversion(uint8_t adc_pin) {
|
187
|
187
|
const adc1_channel_t chan = get_channel(adc_pin);
|
188
|
188
|
uint32_t mv;
|
189
|
189
|
esp_adc_cal_get_voltage((adc_channel_t)chan, &characteristics[attenuations[chan]], &mv);
|
|
190
|
+ HAL_adc_result = mv * 1023.0 / 3300.0;
|
190
|
191
|
|
191
|
192
|
// Change the attenuation level based on the new reading
|
192
|
193
|
adc_atten_t atten;
|
193
|
194
|
if (mv < thresholds[ADC_ATTEN_DB_0] - 100)
|
194
|
|
- adc1_set_attenuation(chan, ADC_ATTEN_DB_0);
|
|
195
|
+ atten = ADC_ATTEN_DB_0;
|
195
|
196
|
else if (mv > thresholds[ADC_ATTEN_DB_0] - 50 && mv < thresholds[ADC_ATTEN_DB_2_5] - 100)
|
196
|
|
- adc1_set_attenuation(chan, ADC_ATTEN_DB_2_5);
|
|
197
|
+ atten = ADC_ATTEN_DB_2_5;
|
197
|
198
|
else if (mv > thresholds[ADC_ATTEN_DB_2_5] - 50 && mv < thresholds[ADC_ATTEN_DB_6] - 100)
|
198
|
|
- adc1_set_attenuation(chan, ADC_ATTEN_DB_6);
|
|
199
|
+ atten = ADC_ATTEN_DB_6;
|
199
|
200
|
else if (mv > thresholds[ADC_ATTEN_DB_6] - 50)
|
200
|
|
- adc1_set_attenuation(chan, ADC_ATTEN_DB_11);
|
|
201
|
+ atten = ADC_ATTEN_DB_11;
|
|
202
|
+ else return;
|
201
|
203
|
|
202
|
|
- HAL_adc_result = mv * 1023.0 / 3300.0;
|
|
204
|
+ adc1_set_attenuation(chan, atten);
|
203
|
205
|
}
|
204
|
206
|
|
205
|
207
|
void analogWrite(pin_t pin, int value) {
|