I have a led and a photodiode, to eliminate noise I’m trying to blink the Led at 3 kHz and then trying to read the analog value at the same frequency.
My first try was using blinkwithout delay, and every time I would say HIGH or LOW I also read the photodiode value. The problem is as I increase the code complexity (moving averages, etc) the frequency decreases and it’s not very stable.
My second try was using the tone function. I can blink the led at 3 kHz in a stable matter without being affected by the code, but how can I analogRead at the same frequency? Could I connect the tone pin to a digital pin to set as a clock someway? Or should I change the code behind the tone function?
Thanks in advance