Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reading on every update()? #7

Closed
brianjmurrell opened this issue Jan 12, 2018 · 5 comments
Closed

reading on every update()? #7

brianjmurrell opened this issue Jan 12, 2018 · 5 comments

Comments

@brianjmurrell
Copy link

I think, looking at the source for your library, that you are reading the analog input on every iteration through the main Arduino loop(), yes?

Is that necessary? Wouldn't it be hard on a battery powered application?

@brianjmurrell
Copy link
Author

Hrm. Battery aside, updating -- actually calling analogRead() I would guess -- on every loop iteration affects other things. For example, on an ESP8266, it causes the WiFi module to go non-responsive.

If I call .update() in every loop() cycle, my module only responds to ping for a few seconds after reboot and then stops. If I only call .update() once per second, this does not happen.

So, while I can surely add such a delay to all of my sketches, I think it needs to be reconsidered if this library really ought to be doing an analogRead() as frequently as every loop iteration or whether every user of this library needs to build delay into their sketches or whether this library should have some built in, user settable, sampling delay/rate.

@mikegleasonjr
Copy link

I guess it is you who decide when you call .update(). Examples are provided with an update in the loop but ultimately you choose.

@brianjmurrell
Copy link
Author

Of course, I, and everyone else could write .update() delays/sampling into their main loop()s.

Do you not think doing so right inside the library so that .update() can just be called on every loop iteration is a useful feature of the library? I can most certainly push a PR if you think it's useful enough to merge it.

@mikegleasonjr
Copy link

Not maintainer just a library user. But in my opinion it belongs in userland (deciding when to update).

@dxinteractive
Copy link
Owner

As mikegleasonjr said, the library is only called every loop if you call it every loop. It's deliberately up to you as a dev when to call update, because the frequency at which you call it will affect some of the parameters you'll use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants