diff --git a/solarpump/sayNumber.ino b/solarpump/sayNumber.ino index bfd3846084cff656d4c93f9f21aff1896a2f00e5..9264b5f42e523710b3b49013b4b1820918a39ee6 100644 --- a/solarpump/sayNumber.ino +++ b/solarpump/sayNumber.ino @@ -3,40 +3,40 @@ // says the digit static void sayDigit(int8_t number) { - switch (number) { - case 0: - playFileQueue(SOUND_NULL); - break; - case 1: - playFileQueue(SOUND_EINS); - break; - case 2: - playFileQueue(SOUND_ZWEI); - break; - case 3: - playFileQueue(SOUND_DREI); - break; - case 4: - playFileQueue(SOUND_VIER); - break; - case 5: - playFileQueue(SOUND_FUNF); - break; - case 6: - playFileQueue(SOUND_SECHS); - break; - case 7: - playFileQueue(SOUND_SIEBEN); - break; - case 8: - playFileQueue(SOUND_ACHT); - break; - case 9: - playFileQueue(SOUND_NEUN); - break; - default: - break; - } + switch (number) { + case 0: + playFileQueue(SOUND_NULL); + break; + case 1: + playFileQueue(SOUND_EINS); + break; + case 2: + playFileQueue(SOUND_ZWEI); + break; + case 3: + playFileQueue(SOUND_DREI); + break; + case 4: + playFileQueue(SOUND_VIER); + break; + case 5: + playFileQueue(SOUND_FUNF); + break; + case 6: + playFileQueue(SOUND_SECHS); + break; + case 7: + playFileQueue(SOUND_SIEBEN); + break; + case 8: + playFileQueue(SOUND_ACHT); + break; + case 9: + playFileQueue(SOUND_NEUN); + break; + default: + break; + } } // Same as sayNumber(int32_t n) only for 1 it says EIN instead of EINS. @@ -57,7 +57,7 @@ static void sayAftNumber(int32_t number) { void sayNumber(int32_t number) { // Negative numbers are spoken the same way as positive numbers only with "Minus" at the beginning. if (number < 0) { - playFileQueue(SOUND_MINUS); + playFileQueue(SOUND_MINUS); sayNumber(-number); // 1-digit numbers } else if (number < 10) { @@ -67,10 +67,10 @@ void sayNumber(int32_t number) { // extra cases for 11 and 12 switch (number) { case 11: - playFileQueue(SOUND_ELF); + playFileQueue(SOUND_ELF); break; case 12: - playFileQueue(SOUND_ZWOLF); + playFileQueue(SOUND_ZWOLF); break; default: // German specific: Say the 1-digit first, then the 10-digit @@ -81,7 +81,7 @@ void sayNumber(int32_t number) { sayPreNumber(ones); // UND only for numbers > 20. (VierUNDzwanzig, but not VierUNDzehn.) if (tens >= 2) - playFileQueue(SOUND_UND); + playFileQueue(SOUND_UND); } // then say the 10-digit switch (tens) { @@ -123,7 +123,7 @@ void sayNumber(int32_t number) { sayPreNumber(hundreds); playFileQueue(SOUND_HUNDERT); sayAftNumber(number - 100 * hundreds); - } + } } /* diff --git a/solarpump/solarpump.ino b/solarpump/solarpump.ino index 56c828c8f75acb3dbf9613100d03be7c20f15b12..1c8c0451e146e8e5c5ec93477b7e858ae507e93b 100644 --- a/solarpump/solarpump.ino +++ b/solarpump/solarpump.ino @@ -27,7 +27,7 @@ static int8_t checkButton() { } // 5 C temperature difference turns a pump on -const float ONTEMPDIFF = 5.0; +const float ONTEMPDIFF = 20.0; // At 1 C difference it turns off again const float OFFTEMPDIFF = 1.0; @@ -35,13 +35,13 @@ void controlPump(uint8_t pumpPin, float tempUp, float tempDown) { // pump is turned on if (digitalRead(pumpPin)) { // turn it off if the difference is less than OFFTEMPDIFF - if (tempUp - tempDown < ONTEMPDIFF) { + if (tempUp < tempDown + OFFTEMPDIFF) { digitalWrite(pumpPin, LOW); } // pump is turned off } else { // turn it on if the difference is more than ONTEMPDIFF - if (tempUp - tempDown > ONTEMPDIFF) { + if (tempUp > tempDown + ONTEMPDIFF) { digitalWrite(pumpPin, HIGH); } } @@ -159,8 +159,12 @@ void displayLight(bool turnOn) { void setup(void) { lcd.init(); + Serial.begin(9600); + // start the relevant libraries used by temperature.cpp temperatureBegin(); + // TESTING: temp1up with a poti + pinMode(A0, INPUT); // start the mp3 library mp3Setup(); diff --git a/solarpump/temperature.ino b/solarpump/temperature.ino index eb51c0223e335dbb72458d32b1ae6f9705a8dafc..b4ed0614be9319bda413e6fbe68b726543818eae 100644 --- a/solarpump/temperature.ino +++ b/solarpump/temperature.ino @@ -4,13 +4,14 @@ #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; +// TESTING: only 10 seconds for testing +const uint32_t ERRORTIME = 10000; // Update the temperature only every second const uint32_t TEMPUPDATETIME = 1000; -/* +/* * 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 @@ -20,23 +21,24 @@ const uint32_t TEMPUPDATETIME = 1000; * 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 + // only update once a second if (curMillis - prevMillis < TEMPUPDATETIME) { return UNCHANGED; } - // get temperature from sensor + // get temperature from sensor dallasTemps.requestTemperatures(); float tempC = dallasTemps.getTempCByIndex(0); - // check if error occured + // check if error occured if (tempC == DEVICE_DISCONNECTED_C) { if (errorStartMillis) { - // check if error occurred longer than some seconds (10s) + // check if error occurred longer than some seconds (10s) if (curMillis - errorStartMillis > ERRORTIME) { return LONG_TIME_ERROR; } @@ -46,7 +48,37 @@ UPDATESTATE t1up(float* temp) { return ERROR; } - // update temperature and time variables + // update temperature and time variables + *temp = tempC; + errorStartMillis = 0; + prevMillis = curMillis; + return SUCCESS; +} +*/ +// TESTING: Using poti for testing +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; + } + float tempC = (float)map(analogRead(A0), 0, 1023, 0, 100); + // check if error occured + if (tempC == 0 || tempC == 100) { + if (errorStartMillis) { + // check if error occurred longer than some seconds (10s) + if (curMillis - errorStartMillis > ERRORTIME) { + return LONG_TIME_ERROR; + } + } else { + errorStartMillis = curMillis; + } + return ERROR; + } + + // update temperature and time variables *temp = tempC; errorStartMillis = 0; prevMillis = curMillis; @@ -136,7 +168,8 @@ UPDATESTATE t2down(float* temp) { // start the relevant libraries void temperatureBegin(void) { - dallasTemps.begin(); + // TESTING + //dallasTemps.begin(); dhtT1down.begin(); dhtT2up.begin(); dhtT2down.begin();