#include "wattlight.h" Wattlight::Wattlight () { count = 0; haveold = false; avgus = 0; } unsigned int Wattlight::pulses () { unsigned int result; noInterrupts(); result = count; interrupts(); return result; } void Wattlight::readout () { noInterrupts(); if (count) { avgus = (us-oldus)/count; oldus = us; oldcount = count; count = 0; } else { if (avgus && haveold) { unsigned long newavg = micros()-oldus; if (newavg>avgus) avgus = newavg; } oldcount = 0; } interrupts(); }