diff --git a/solarpump/solarpump.ino b/solarpump/solarpump.ino index 67cc7e9f346c2b8a2269c4c8942fb4524837507f..56c828c8f75acb3dbf9613100d03be7c20f15b12 100644 --- a/solarpump/solarpump.ino +++ b/solarpump/solarpump.ino @@ -50,7 +50,7 @@ void controlPump(uint8_t pumpPin, float tempUp, float tempDown) { /* * prints a float where the decimals specify the numbers of digit, which are printed, * after the decimal point and - * rightPad specifies the total length printed, where empty spots are filled with spaces + * rightPad specifies the total length printed, where empty spots are filled with spaces */ void printFloat(float f, uint8_t decimals, uint8_t rightPad) { String s = String(f, decimals); @@ -145,7 +145,7 @@ void displayLight(bool turnOn) { lcd.backlight(); prevMillis = millis(); curState = true; - // turn off after lightMillis ms + // turn off after lightMillis (30 000 ms) } else if (curState && millis() - prevMillis > lightMillis) { lcd.noBacklight(); curState = false; diff --git a/solarpump/soundFiles.h b/solarpump/soundFiles.h index 8a31b014c986384d11fb269743591933fda4465a..9fc1dbaef4e340074293e238ef7ab955338e4732 100644 --- a/solarpump/soundFiles.h +++ b/solarpump/soundFiles.h @@ -1,8 +1,10 @@ #ifndef SOUNDFILES_H #define SOUNDFILES_H -// index for the sound files for mp3 module TDB380 -// the files are .mp3 instead of .wav +/* + * index for the sound files for mp3 module TDB380 + * the files are .mp3 instead of .wav + */ #define SOUND_NULL 33 // A033.wav #define SOUND_EIN 1 // A001.wav #define SOUND_EINS 44 // A044.wav diff --git a/solarpump/temperature.ino b/solarpump/temperature.ino index a4e9243ddb85ef7dac9fc2f5e915073082545960..eb51c0223e335dbb72458d32b1ae6f9705a8dafc 100644 --- a/solarpump/temperature.ino +++ b/solarpump/temperature.ino @@ -4,25 +4,39 @@ #include <DHT.h> /* No new valid temperature for < 60 seconds? I sleep. - * No new valid temperature for > 60 seconds? REAL PROBLEM! */ + * No new valid temperature for > 60 seconds? REAL PROBLEM! + */ const uint32_t ERRORTIME = 10000; // Update the temperature only every second const uint32_t TEMPUPDATETIME = 1000; -// UP temperature for solar system 1 +/* + * UP temperature for solar system 1 + * 1. update only after a second (TEMPUPDATETIME) otherwise return UNCHANGED + * 2. get temperature from temperatur sensor check for errors + * 3. return ERROR if error occured first time + * 4. if error occurred longer than 10 s (ERRORTIME) return LONG_TIME_ERROR + * 5. update temperatur, time variables and return SUCCESS + * function below work the same, except that they use another + * temperature sensor library + */ static OneWire oneWireT1up(T1UP); static DallasTemperature dallasTemps(&oneWireT1up); UPDATESTATE t1up(float* temp) { static uint32_t prevMillis = 0; static uint32_t errorStartMillis = 0; uint32_t curMillis = millis(); + // only update once a second if (curMillis - prevMillis < TEMPUPDATETIME) { return UNCHANGED; } + // get temperature from sensor dallasTemps.requestTemperatures(); float tempC = dallasTemps.getTempCByIndex(0); + // check if error occured if (tempC == DEVICE_DISCONNECTED_C) { if (errorStartMillis) { + // check if error occurred longer than some seconds (10s) if (curMillis - errorStartMillis > ERRORTIME) { return LONG_TIME_ERROR; } @@ -32,6 +46,7 @@ UPDATESTATE t1up(float* temp) { return ERROR; } + // update temperature and time variables *temp = tempC; errorStartMillis = 0; prevMillis = curMillis;