#include //library needed for hall_sensor_read to work const unsigned long duration = 10 * 60 * 1000; // 10 minutes in milliseconds const unsigned long interval = 1000; // 1 second interval between readings void setup() { Serial.begin(115200); //BAUD rate } void loop() { unsigned long start_time = millis(); // start time for average calculations unsigned long end_time = start_time + duration; // end time for average calculations int max_value = -800; //max variable int min_value = 800; //min variable long sum = 0; // sum of readings unsigned int count = 0; // count for sensor readings unsigned int avg_count = 0; //count for total number of averages taken float total_sum = 0; //total sum of all averages float roll_avg = 0; //rolling average variable while (millis() < end_time) { //10 minute average function int sensor_value = hall_sensor_read(); //creates variable sensor_value equal to value of hall read function sum += sensor_value; //adds the current sensor value to the sum variable count++; //interates the count variable one if (hall_sensor_read() > max_value) { //checks for new max value max_value = hall_sensor_read(); } if (hall_sensor_read() < min_value) { //checks for new min value min_value = hall_sensor_read(); } delay(interval); //waits the interval value before looping } if (count != 0) { // check if valid readings were obtained float average = (float)sum / count; // calculate the average total_sum += average; //add the average value to the total sum variable avg_count++; //interates the avg_count one roll_avg = (total_sum / avg_count); //rolling average function //Following code prints all values of interest to serial for reference and collection Serial.print("Average value: "); Serial.println(average); Serial.print("Max value: "); Serial.println(max_value); Serial.print("Min value: "); Serial.println(min_value); Serial.print("Rolling average: "); Serial.println(roll_avg); } else { Serial.println("No valid readings obtained."); //incase ESP32 messes up and doesn't get number values } delay(1000); }