Sming - Open Source framework for high efficiency native ESP8266 development

User avatar
By frankDownunder
#40016 Im guessing you mean ADC rather than ACD? And no example yet (see forum reply http://www.esp8266.com/viewtopic.php?f=35&t=5987&start=5 from "hreintke" )
Its straightforward though - I use system_adc_read(), on a callback to a timer, I flash a LED so I know something is happening, and I stuff the result into a circularBuffer which I can deal with later.
Code: Select allvoid AS103::onTimerReadCurrent()
{
   static uint8_t f = 0;   f++;   f = f % 16;   
   digitalWrite(LED_WHITE, f>12? HIGH: LOW);
   int reading = system_adc_read();
   circularBuffer.push_back(reading);
}
.  .  .
timer.initializeMs(samplePeriodMs, TimerDelegate(&AS103::onTimerReadCurrent, this)).start();

I found though that if samplePeriodMs is too low and I do it too often, I get a reset. Every 5ms is OK it would seem.