From 446a70528926663728eae536e8e3d73ebdcd751f Mon Sep 17 00:00:00 2001 From: JChristensen Date: Fri, 30 Mar 2018 20:47:06 -0400 Subject: [PATCH] Add comments. --- src/movingAvg.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/movingAvg.cpp b/src/movingAvg.cpp index ce65055..8f84235 100644 --- a/src/movingAvg.cpp +++ b/src/movingAvg.cpp @@ -14,11 +14,13 @@ void movingAvg::begin() // add a new reading and return the new moving average int movingAvg::reading(int newReading) { + // add each new data point to the sum until the m_readings array is filled if (m_nbrReadings < m_interval) { ++m_nbrReadings; m_sum = m_sum + newReading; } + // once the array is filled, subtract the oldest data point and add the new one else { m_sum = m_sum - m_readings[m_next] + newReading;