Does anyone know, is it possible to change ADC_MODE from ADC_VCC to ADC_TOUT dynamically

Does anyone know, is it possible to change ADC_MODE from ADC_VCC to ADC_TOUT dynamically (in program), or is it a compile-time directive?

En Lúa almenos es necesario hacer un reset para que los cambios surtan efecto.

http://nodemcu.readthedocs.io/en/master/en/modules/adc/

Gracis. Looks like it is possible, I’ll have to see how the code behind Lua accomplishes this.

It seems not possible with the esp8266 arduino core, docs here advise ADC_MODE(ADC_VCC); must be called outside of all functions: https://github.com/esp8266/Arduino/blob/master/doc/reference.md#analog-input

The reason why it has to happen outside a function: ADC_MODE is just a macro which expands to a function declaration:

You can probably just copy and paste in the function definition into your sketch… and have it return the desired mode.

That’s actually a really good suggestion, definitely worth a try.