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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions HX711.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool HX711::is_ready() {
return digitalRead(DOUT) == LOW;
}

void HX711::set_gain(byte gain) {
long HX711::set_gain(byte gain) {
switch (gain) {
case 128: // channel A, gain factor 128
GAIN = 1;
Expand All @@ -39,7 +39,8 @@ void HX711::set_gain(byte gain) {
}

digitalWrite(PD_SCK, LOW);
read();
// read one more value with old gain/channel to update settings
return read();
}

long HX711::read() {
Expand Down
4 changes: 2 additions & 2 deletions HX711.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class HX711
// input PD_SCK should be low. When DOUT goes to low, it indicates data is ready for retrieval.
bool is_ready();

// set the gain factor; takes effect only after a call to read()
// set the gain factor; read() is invoked to set the new gain and its return value is returned
// channel A can be set for a 128 or 64 gain; channel B has a fixed 32 gain
// depending on the parameter, the channel is also set to either A or B
void set_gain(byte gain = 128);
long set_gain(byte gain = 128);

// waits for the chip to be ready and returns a reading
long read();
Expand Down