Skip to content
Closed
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
14 changes: 13 additions & 1 deletion HX711.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include <Arduino.h>
#include <HX711.h>

#if ARDUINO_VERSION <= 106
#ifndef ARDUINO_ARCH_ESP8266
// "yield" is not implemented as noop in older Arduino Core releases, so let's define it.
// See also: https://stackoverflow.com/questions/34497758/what-is-the-secret-of-the-arduino-yieldfunction/34498165#34498165
void yield(void) {};
#endif

#ifdef ARDUINO_ARCH_ESP8266
#define USE_WDT
#endif

HX711::HX711(byte dout, byte pd_sck, byte gain) {
begin(dout, pd_sck, gain);
}
Expand Down Expand Up @@ -52,7 +56,11 @@ long HX711::read() {
// wait for the chip to become ready
while (!is_ready()) {
// Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
#ifdef USE_WDT
ESP.wdtFeed();
#else
yield();
#endif
}

unsigned long value = 0;
Expand Down Expand Up @@ -90,7 +98,11 @@ long HX711::read_average(byte times) {
long sum = 0;
for (byte i = 0; i < times; i++) {
sum += read();
#ifdef USE_WDT
ESP.wdtFeed();
#else
yield();
#endif
}
return sum / times;
}
Expand Down