user10270: I am using sdFat library the analog bin logger example, 
Github: SdFat/SdFat/examples/AnalogBinLogger/

The program is working fine and every thing but the thing is, this high speed datalogger uses interrupts and timers to make the ADC work at a pre-determined sampling frequency and it DOES NOT use the normal analogRead ()
What I want is, when the input of some analog pin is bellow a pre-determined value, I want to write HIGH or LOW to some digital pin, 
my question is, how can I compare the new sample in the analog bin logger example as I simply want to compare the new sample as in:
if ( analogRead() < 256 ) {// do something}

knowing that there is no analogRead() in the program because it uses timers and interrupts.

user4143: In the function
ISR(ADC_vect) {

the variable d contains the current sample:
  // Read ADC data.
#if RECORD_EIGHT_BITS
  uint8_t d = ADCH;
#else  // RECORD_EIGHT_BITS
  // This will access ADCL first.
  uint16_t d = ADC;
#endif  // RECORD_EIGHT_BITS

So you can just "do something" depending on what is in d.  Of course, since this is a timer interrupt you have limited time to do anything, so you need to make sure that whatever you do is fast and efficient - so really you want to be using direct port access instead of digitalWrite().

10270: <p>I am using sdFat library the analog bin logger example, </p>

<p><a href="https://github.com/greiman/SdFat/tree/master/SdFat/examples/AnalogBinLogger" rel="nofollow">Github: SdFat/SdFat/examples/AnalogBinLogger/
</a></p>

<p>The program is working fine and every thing but the thing is, this high speed datalogger uses interrupts and timers to make the ADC work at a pre-determined sampling frequency and it DOES NOT use the normal <code>analogRead ()</code></p>

<p>What I want is, when the input of some analog pin is bellow a pre-determined value, I want to write HIGH or LOW to some digital pin, 
my question is, how can I compare the new sample in the analog bin logger example as I simply want to compare the new sample as in:</p>

<pre><code>if ( analogRead() &lt; 256 ) {// do something}
</code></pre>

<p>knowing that there is no analogRead() in the program because it uses timers and interrupts.</p>
 4143: <p>In the function</p>

<pre><code>ISR(ADC_vect) {
</code></pre>

<p>the variable <code>d</code> contains the current sample:</p>

<pre><code>  // Read ADC data.
#if RECORD_EIGHT_BITS
  uint8_t d = ADCH;
#else  // RECORD_EIGHT_BITS
  // This will access ADCL first.
  uint16_t d = ADC;
#endif  // RECORD_EIGHT_BITS
</code></pre>

<p>So you can just "do something" depending on what is in <code>d</code>.  Of course, since this is a timer interrupt you have limited time to do anything, so you need to make sure that whatever you do is fast and efficient - so really you want to be using direct port access instead of digitalWrite().</p>
