Skip to content

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

Open
Nagasaki45 wants to merge 1 commit into
bogde:masterfrom
Nagasaki45:master
Open

'set_gain' returns the last value of 'read'#55
Nagasaki45 wants to merge 1 commit into
bogde:masterfrom
Nagasaki45:master

Conversation

@Nagasaki45
Copy link
Copy Markdown

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