Skip to content

Commit

Permalink
Add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
JChristensen committed Mar 31, 2018
1 parent af4de20 commit 446a705
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/movingAvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 446a705

Please sign in to comment.