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]));
}
asked Sep 26, 2020 at 13:15
1
  • 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. Commented Sep 26, 2020 at 14:01

1 Answer 1

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]));
}
answered Sep 26, 2020 at 14:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.