diff --git a/include/flow.h b/include/flow.h index 8fb95f8..2ce4b6b 100644 --- a/include/flow.h +++ b/include/flow.h @@ -20,7 +20,7 @@ void flow_setup() { } void flow_loop(unsigned long loopmillis) { - if (loopmillis>=last_read_flow+READINTERVAL_FLOW) { + if (loopmillis>=last_read_flow+READINTERVAL_FLOW) { flow=flow_counter*1000.0/(loopmillis-last_read_flow)/2.0; //Frequency [Hz] flow/=flow_factor; //[L/min] diff --git a/src/main.cpp b/src/main.cpp index ddc6549..7498e4b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,18 +85,19 @@ void loop() { flag_print=false; - ec_loop(loopmillis); + + //ec_loop(loopmillis); - temperature_loop(loopmillis); + //temperature_loop(loopmillis); - waterlevel_loop(loopmillis); + //waterlevel_loop(loopmillis); flow_loop(loopmillis); - sm_loop(loopmillis); + //sm_loop(loopmillis); static bool getReading=false; @@ -108,8 +109,42 @@ void loop() { digitalWrite(PIN_LED,HIGH); } + static bool started=false; + static bool ended=false; + static unsigned long started_time=0; + static unsigned long ended_time=0; + - if (loopmillis>last_print+2000) { + if (flow_counter_sum>10 && !started && !ended) { //start + started=true; + started_time=millis(); + Serial.println("Started!"); + } + static uint32_t last_flow_counter_sum=0; + if (loopmillis>last_print+1000) { //test check + last_print=loopmillis; + if (started && !ended) { + Serial.println(flow_counter_sum-last_flow_counter_sum); + if (flow_counter_sum-last_flow_counter_sum<=2){ //stopped + ended=true; + ended_time=millis(); + Serial.println("Ended!"); + } + + last_flow_counter_sum=flow_counter_sum; + + } + if (ended) { + Serial.println("counts,time"); + Serial.print(flow_counter_sum); + Serial.print(","); + Serial.print((ended_time-started_time)/1000.0); + Serial.println(); + delay(10000); + } + } + + if (loopmillis>last_print+2000 && 1==2) { //if (ec_flag_measurement_available && getReading) { if (ec_flag_measurement_available) { last_print=loopmillis; @@ -119,6 +154,7 @@ void loop() { Serial.print(millis()/1000.0,2); Serial.print(","); + /* Serial.print(getMeanf(tempCmean_reservoir,TEMPMEAN_SIZE)); Serial.print(","); //Serial.print(getMean(sm_mean,SM_SIZE)); Serial.print(","); @@ -127,6 +163,8 @@ void loop() { Serial.print(ec_adc_adjusted); //Serial.print(","); //Serial.print(ec); Serial.print(","); //Serial.print(ec25); + */ + Serial.println();