everything is working now except for adding my flow reading to itself each loop to then divide by the number of total reads.
I'm trying to add a sample of my smoothedflow every time around as this variable has already been averaged over 5 seconds. It is just remaining at the value of smoothedflow without adding anything to it. The number of total reads is now increasing as it should.
I've tried the method shown and tried smoothedflow++ and a couple other things I've seen online but I'm stuck.
I'm trying to add a sample of my smoothedflow every time around as this variable has already been averaged over 5 seconds. It is just remaining at the value of smoothedflow without adding anything to it. The number of total reads is now increasing as it should.
I've tried the method shown and tried smoothedflow++ and a couple other things I've seen online but I'm stuck.
Code:
// Smoothed Flow Rate
float sumvala = 0; //create sumval variable
for (int i=0; i <= 49; i++){ //repeat this code 50 times
sumvala = flow + sumvala; //add read value to sum
delay(100); //0.1 second delay
}
float smoothedflow = 0; //create smoothedflow variable
smoothedflow = sumvala/50; //divide sum by 50
Serial.print("Smoothed flow is : "); //print out results
Serial.print(smoothedflow);
Serial.println("gpm");
float sumvalb = 0;
sumvalb = smoothedflow + sumvalb;
totalreads++;
float avgflow = 0;
avgflow = sumvalb/totalreads;
Serial.print("Average flow is : "); //print out results
Serial.print(avgflow);
Serial.println("gpm");
Serial.print("sumvalb is : ");
Serial.print(sumvalb);
Serial.println("gal");
Serial.print("Total Reads : ");
Serial.print(totalreads);
Serial.println("Reads");