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]));
}
-
2You 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– Delta_G2020年09月26日 14:01:05 +00:00Commented Sep 26, 2020 at 14:01
1 Answer 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]));
}