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

'set_gain' returns the last value of 'read' #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nagasaki45
Copy link

When two load cells are connected to one HX711 it is a trivial use case to read both channels in a loop. Currently it looks something like this:

void loop() {
  scale.set_gain(64);
  long loadA = scale.read();
  scale.set_gain(32);
  long loadB = scale.read();
  // Do something with readings...
}

In such scenario, under the hood there are 4 calls to read which slow down everything significantly.

With this change, this use case can be solved efficiently with:

void loop() {
  long loadB = scale.set_gain(32);
  long loadA = scale.set_gain(64);
  // Do something with readings...
}

I know that it an awefull interface to work with, as the set_scale method already does too many things. However, I couldn't find a better yet simple way to both read and update efficiently. If you have a better solution I would like to hear!

Note that this change shouldn't break existing code (AFAIK, I'm not a C++ dev).

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

Successfully merging this pull request may close these issues.

1 participant