1

Can we use just a analog Read without storing it

i hear it it a good practice to take two reads

for better accuracy

example:

// Read extra analog inputs
    for (int i = 0; i < 8; i++)
{
    // Read analog pin to nothing.
        analogRead(i]); // analog-read is not writing to anything 
}

// Read the analog inputs for (int i = 0; i < length; i++) { // Write the state of the analog pin to the response buffer. slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i])); }

Eric V
  • 55
  • 5
  • 2
    You only need to do that if you are changing pins between reads in free running mode. The way you’ve done it here wouldn’t work because you change pins after your dummy read. You’d want to read the same pin twice in a row. But yes, you can call the function without storing the result to answer your question. – Delta_G Sep 26 '20 at 14:01

1 Answers1

1

how about this ?

// Read the analog inputs
for (int i = 0; i < length; i++)
{
    analogRead(analog_pins[address + i]); // for pre read
// Write the state of the analog pin to the response buffer.
slave.writeRegisterToBuffer(i, analogRead(analog_pins[address + i]));

}

Eric V
  • 55
  • 5