// ************************************************************************************************
//
// Documentation for this, and the rest of the LC libraies that make this up.
// Here's the book : https://github.com/leftCoast/LC_libraryDocs/blob/main/LC_libraries.pdf
// Search for : timeObj & runningAvg
//
// ************************************************************************************************
#include <timeObj.h>
#include <runningAvg.h>
#define MS_PER_READING 1000
#define NUM_READINGS 10
timeObj readingTimer(MS_PER_READING); // A timer.
runningAvg smoother(NUM_READINGS); // A smoother. (running average).
float result; // The global result value.
void setup() {
Serial.begin(115200);
// Other setup() things.
}
void loop() {
if (readingTimer.ding()) { // If the timer expires..
result = smoother.addData(analogRead(A0)); // Take reading and get avearage result.
Serial.print("Reading : "); // Send it out to Mrs user.
Serial.println(result,2); // This too.
readingTimer.stepTime(); // Reset the timer for next reading.
} //
// Do other loop() things.
}