fix weight string vanishing
This commit is contained in:
parent
75b720f564
commit
03b9779198
|
@ -13,7 +13,7 @@ platform = atmelavr
|
|||
board = nanoatmega328
|
||||
framework = arduino
|
||||
|
||||
monitor_speed = 9600
|
||||
monitor_speed = 115200
|
||||
|
||||
lib_deps=
|
||||
bogde/HX711@^0.7.5
|
||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -104,7 +104,7 @@ unsigned long time_adcwait=1000/spsadc;
|
|||
int adc_readings=1; //ca. 700ms for 5 readings, ca 75ms for 1 reading, readings=1 10times = 747ms
|
||||
|
||||
double weight=0;
|
||||
#define ADCMEDIANVALUES_MAX 31 //needs to be uneven, maximum number, for array declaration
|
||||
#define ADCMEDIANVALUES_MAX 93 //needs to be uneven, maximum number, for array declaration
|
||||
float weightseries[ADCMEDIANVALUES_MAX]; //last n values for median filter
|
||||
uint16_t adcmedianvalues=DEFAULT_ADCMEDIANVALUES; //needs to be uneven //eeprom
|
||||
float adcFilterKeepMedianvaluesFactor=0.8; //how many lowest and highest values will be removed from the array before avaraging (as factor). 0.0 means only median is used. 1.0 means all values are used.
|
||||
|
@ -190,7 +190,7 @@ void updateLCD();
|
|||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
|
||||
pinMode(PIN_LED, OUTPUT);
|
||||
digitalWrite(PIN_LED, HIGH);
|
||||
|
@ -300,7 +300,7 @@ void loop() {
|
|||
currentreading_pos++;
|
||||
currentreading_pos%=N_CURRENTREADINGS;
|
||||
|
||||
|
||||
double showweight=getWeightFiltered();
|
||||
switch(state){
|
||||
case S_SCALEDISPLAY:
|
||||
if ((getWeightSeriesMax()-getWeightSeriesMin())<LCD_BACKLIGHT_WEIGHT){
|
||||
|
@ -315,7 +315,9 @@ void loop() {
|
|||
lcd0=toStringBar(weight,0,1000);
|
||||
//lcd1=toWeightString(weight)+"g";
|
||||
//lcd1=toWeightString(getWeightMedian())+"g";
|
||||
lcd1=toWeightString(getWeightFiltered())+"g";
|
||||
|
||||
lcd1=toWeightString(showweight)+"g";
|
||||
Serial.print(showweight,3); Serial.println("g");
|
||||
|
||||
//___
|
||||
if (btn_back_press==2){ //press BACK to tare
|
||||
|
@ -569,7 +571,8 @@ void loop() {
|
|||
if (millis() >= time_lastadc+time_adcwait)
|
||||
{
|
||||
weight=scale.get_units(adc_readings);
|
||||
adcmedianposition++; if (adcmedianposition>=adcmedianvalues) adcmedianposition=0;
|
||||
adcmedianposition++;
|
||||
adcmedianposition%=adcmedianvalues;
|
||||
weightseries[adcmedianposition]=weight; //save weight to series for medianfilter
|
||||
looptimeadc_margin=millis()-time_lastadc-time_adcwait;
|
||||
|
||||
|
@ -996,15 +999,16 @@ float getWeightSeriesMax()
|
|||
}
|
||||
|
||||
String toWeightString(double w){
|
||||
return toWeightString(w,5,4);
|
||||
return toWeightString(w,2,6);
|
||||
}
|
||||
String toWeightString(double w,uint8_t dec,uint8_t len){
|
||||
char outstring[16];
|
||||
char vz;
|
||||
if(w<0)
|
||||
vz='-';
|
||||
else
|
||||
vz='+';
|
||||
if(w<0) {
|
||||
vz='-';
|
||||
}else{
|
||||
vz='+';
|
||||
}
|
||||
dtostrf(abs(w),len,dec,outstring);
|
||||
return String(vz)+""+String(outstring);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue