more efficient display update
This commit is contained in:
parent
81821be685
commit
2457d6ee51
10
src/main.cpp
10
src/main.cpp
|
@ -28,7 +28,9 @@ uint8_t display_data[] = { 0xff, 0xff, 0xff, 0xff };
|
||||||
uint8_t display_blank[] = { 0x00, 0x00, 0x00, 0x00 };
|
uint8_t display_blank[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
unsigned long last_displayupdate=0;
|
unsigned long last_displayupdate=0;
|
||||||
#define DISPLAYUPDATEINTERVAL 100
|
#define DISPLAYUPDATEINTERVAL 100 //maximum time to update display
|
||||||
|
#define DISPLAYUPDATEINTERVAL_MIN 10 //minimum display update time
|
||||||
|
bool update_display=true;
|
||||||
|
|
||||||
|
|
||||||
#include "HX711.h"
|
#include "HX711.h"
|
||||||
|
@ -162,6 +164,7 @@ void loopHandler() {
|
||||||
if (spread<MAXSPREAD_TARE) { //if reading is stable
|
if (spread<MAXSPREAD_TARE) { //if reading is stable
|
||||||
if (weight_filtered<weight_tare) { //new min
|
if (weight_filtered<weight_tare) { //new min
|
||||||
weight_tare=weight_filtered;
|
weight_tare=weight_filtered;
|
||||||
|
update_display=true;
|
||||||
Serial.print("new tare="); Serial.println(weight_tare,3);
|
Serial.print("new tare="); Serial.println(weight_tare,3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +172,7 @@ void loopHandler() {
|
||||||
if (spread<MAXSPREAD_MEASURE) { //if reading is stable
|
if (spread<MAXSPREAD_MEASURE) { //if reading is stable
|
||||||
if (weight_filtered>weight_max) { //new max
|
if (weight_filtered>weight_max) { //new max
|
||||||
weight_max=weight_filtered;
|
weight_max=weight_filtered;
|
||||||
|
update_display=true;
|
||||||
Serial.print("new max="); Serial.println(weight_max,3);
|
Serial.print("new max="); Serial.println(weight_max,3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,6 +181,7 @@ void loopHandler() {
|
||||||
if (!weight_sent) {
|
if (!weight_sent) {
|
||||||
if (weight_max-weight_tare>MIN_WEIGHT_DIFFERENCE) {
|
if (weight_max-weight_tare>MIN_WEIGHT_DIFFERENCE) {
|
||||||
sendWeight(weight_max-weight_tare);
|
sendWeight(weight_max-weight_tare);
|
||||||
|
update_display=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,8 +211,9 @@ void loopHandler() {
|
||||||
powerOff();
|
powerOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loopmillis > last_displayupdate + DISPLAYUPDATEINTERVAL) {
|
if ( (loopmillis > last_displayupdate + DISPLAYUPDATEINTERVAL) | (update_display && (loopmillis > last_displayupdate + DISPLAYUPDATEINTERVAL_MIN) )) {
|
||||||
last_displayupdate=loopmillis;
|
last_displayupdate=loopmillis;
|
||||||
|
update_display=false; //reset flag
|
||||||
displayNumber(weight_current);
|
displayNumber(weight_current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue