12 #ifdef ARDUINO_ARCH_AVR 14 #include "DCCpp_Uno.h" 15 #include "CurrentMonitor.h" 20 void CurrentMonitor::begin(
int pin,
int inSignalPin,
const char *msg,
float inSampleMax)
23 this->signalPin = inSignalPin;
26 this->currentSampleMax = inSampleMax;
29 boolean CurrentMonitor::checkTime()
31 if(millis( ) - sampleTime < CURRENT_SAMPLE_TIME)
33 sampleTime = millis();
37 void CurrentMonitor::check()
39 if (this->pin == UNDEFINED_PIN || this->signalPin == UNDEFINED_PIN)
42 this->current = (float)(analogRead(this->pin) * CURRENT_SAMPLE_SMOOTHING + this->current * (1.0 - CURRENT_SAMPLE_SMOOTHING));
45 if (this->current > this->currentSampleMax && digitalRead(this->signalPin) == HIGH)
47 digitalWrite(this->signalPin, LOW);
48 DCCPP_INTERFACE.print(this->msg);
49 #if !defined(USE_ETHERNET) 50 DCCPP_INTERFACE.println(
"");
55 long int CurrentMonitor::sampleTime=0;