diff --git a/HX711.cpp b/HX711.cpp index 14efb58..04628c3 100644 --- a/HX711.cpp +++ b/HX711.cpp @@ -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; @@ -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() { diff --git a/HX711.h b/HX711.h index 23b2234..da6214a 100644 --- a/HX711.h +++ b/HX711.h @@ -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();