Hi everyone,
Regarding the above subject, I have done some code to show you how to find the mean value of an array. Alas, the code has an array.
#include <Average.h>
double SUB2_cy1[]= {35.92, 35.73, 35.79, 36.15, 35.73, 35.91, 36.14, 35.68, 35.87, 35.53, 35.16, 36.24, 35.7, 35.65, 35.55, 35.53, 36.03, 35.65, 36.22, 35.47, 35.65, 35.74, 35.31, 35.88, 35.36, 35.08, 35.51};
double SUB2_cy2[]= {35.89, 35.59, 35.51, 35.71, 35.48, 35.89, 36.17, 35.73, 35.43, 35.74, 35.65, 35.78, 35.81, 35.21, 35.18, 34.99, 35.84, 35.46, 35.77, 35.85, 36.12, 35.84, 35.74, 35.98, 35.74, 36.3, 36.39};
double SUB2_cy3[]= {35.86, 35.72, 35.84, 35.84, 35.84, 36.16, 36.02, 35.88, 35.93, 35.83, 35.67, 35.55, 35.84, 35.14, 35.67, 35.62, 35.85, 35.84, 35.55, 35.55, 36.02, 35.86, 35.8};
void setup() {
// put your setup code here, to run once:
double arrBBT1 = sizeof( SUB2_cy1 ) / sizeof( double );
double arrBBT2 = sizeof( SUB2_cy2 ) / sizeof( double );
double arrBBT3 = sizeof( SUB2_cy3 ) / sizeof( double );
Serial.begin( 9600 );
while(!Serial);
delay(1000);
Serial.println( arrBBT1 );
Serial.println( arrBBT2 );
Serial.println( arrBBT3 );
double mean_BBT1 = SUB2_cy1.mean;
Serial.print("LIMIT = ");
Serial.println( mean_BBT1 );
}
float average (int * array, int len) // assuming array is int.
{
long sum = 0L ; // sum will be larger than an item, long for safety.
for (int i = 0 ; i < len ; i++)
sum += array [i] ;
return ((float) sum) / len ; // average will be fractional, so float may be appropriate.
}
void loop() {
// put your main code here, to run repeatedly:
}
Could anyone help me, please...
![]()
Thanks.