diff --git a/solarpump/mp3.ino b/solarpump/mp3.ino index c54977d0f1a7769b93a5486fc57d94131498e92e..7b0c7040c62277ff166bfd85d47a45f1e9d91d6b 100644 --- a/solarpump/mp3.ino +++ b/solarpump/mp3.ino @@ -1,3 +1,4 @@ +#include <Arduino.h> #include "pins.h" #include <SoftwareSerial.h> @@ -17,7 +18,7 @@ void mp3Setup(void) { // immediately play a file void playFile(uint8_t fileNumber, bool respectBusyPin) { // do nothing if we want to wait for the BUSY pin - if (respectBusyPin && digitalRead(MP3BUSY)) { + if (respectBusyPin && digitalRead(MP3BUSY) == LOW) { return; } mp3.write(fileNumber); diff --git a/solarpump/solarpump.ino b/solarpump/solarpump.ino index 6c812e04d87141ab41496a84f874bf9469f166b2..e10331c2b0810b3580272e998d45729c808f29ef 100644 --- a/solarpump/solarpump.ino +++ b/solarpump/solarpump.ino @@ -1,4 +1,4 @@ -#include <stdint.h> +#include <Arduino.h> #include "pins.h" #include "temperature.h" #include "mp3.h" @@ -63,7 +63,7 @@ void printFloat(float f, uint8_t decimals, uint8_t rightPad) { /* * display the temperature of the four temperature sensorse and * also shows if the pump is running - * shows no temperature if sensor state is in LONG_TIME_ERROR + * shows no temperature if sensor state is in LONG_TIME_ERROR */ void displayText(float t1up_C, float t1down_C, bool pump1, float t2up_C, float t2down_C, bool pump2, UPDATESTATE state_t1up, UPDATESTATE state_t1down, UPDATESTATE state_t2up, UPDATESTATE state_t2down) { @@ -154,29 +154,33 @@ void displayLight(bool turnOn) { /* * main setup function - * initialize every electronic component + * initialise every electronic component */ -// main setup function void setup(void) { lcd.init(); - Serial.begin(9600); // for debugging // start the relevant libraries used by temperature.cpp temperatureBegin(); + // start the mp3 library mp3Setup(); + // the pumps pinMode(PUMP1, OUTPUT); pinMode(PUMP2, OUTPUT); + // the button pinMode(BUTTON, INPUT_PULLUP); } // say out all the relevant infos via the loudspeaker -void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) -{ +void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) { const uint8_t decimals = 0; + // system 1 playFileQueue(SOUND_EINS); + // up temperature playFileQueue(SOUND_OBEN); + // say the number sayNumber(temp1up, decimals); + // wait a bit playFileQueue(SOUND_STILLE); playFileQueue(SOUND_EINS); @@ -184,6 +188,15 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) sayNumber(temp1down, decimals); playFileQueue(SOUND_STILLE); + playFileQueue(SOUND_PUMPE); + playFileQueue(SOUND_EINS); + if (digitalRead(PUMP1)) { + playFileQueue(SOUND_AN); + } else { + playFileQueue(SOUND_AUS); + } + playFileQueue(SOUND_STILLE); + playFileQueue(SOUND_ZWEI); playFileQueue(SOUND_OBEN); sayNumber(temp2up, decimals); @@ -194,34 +207,12 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) sayNumber(temp2down, decimals); playFileQueue(SOUND_STILLE); - if (digitalRead(PUMP1)) - { - playFileQueue(SOUND_PUMPE); - playFileQueue(SOUND_EINS); - playFileQueue(SOUND_AN); - playFileQueue(SOUND_STILLE); - } - else - { - playFileQueue(SOUND_PUMPE); - playFileQueue(SOUND_EINS); - playFileQueue(SOUND_AUS); - playFileQueue(SOUND_STILLE); - } - - if (digitalRead(PUMP2)) - { - playFileQueue(SOUND_PUMPE); - playFileQueue(SOUND_ZWEI); + playFileQueue(SOUND_PUMPE); + playFileQueue(SOUND_ZWEI); + if (digitalRead(PUMP2)) { playFileQueue(SOUND_AN); - playFileQueue(SOUND_STILLE); - } - else - { - playFileQueue(SOUND_PUMPE); - playFileQueue(SOUND_ZWEI); + } else { playFileQueue(SOUND_AUS); - playFileQueue(SOUND_STILLE); } } @@ -247,21 +238,34 @@ void loop(void) { displayLight(false); } - if (t1up(&t1up_C) == LONG_TIME_ERROR || t1down(&t1down_C) == LONG_TIME_ERROR) { - // TODO: Warning sound + // update the temperatures + UPDATESTATE t1upState = t1up(&t1up_C); + UPDATESTATE t1downState = t1down(&t1down_C); + UPDATESTATE t2upState = t2up(&t2up_C); + UPDATESTATE t2downState = t2down(&t2down_C); + + if (t1upState == LONG_TIME_ERROR || t1downState == LONG_TIME_ERROR || t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) { + // continuously say that there is an error + playFile(SOUND_FEHLER, true); + } + + // control pump of system 1 + if (t1upState == LONG_TIME_ERROR || t1downState == LONG_TIME_ERROR) { // Turn pump on to be safe digitalWrite(PUMP1, HIGH); } else { + // no errors => control pump according to the temperatures controlPump(PUMP1, t1up_C, t1down_C); } - if (t2up(&t2up_C) == LONG_TIME_ERROR || t2down(&t2down_C) == LONG_TIME_ERROR) { - // TODO: Warning sound - // Turn pump on to be safe + + // same for system 2 + if (t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) { digitalWrite(PUMP2, HIGH); } else { controlPump(PUMP2, t2up_C, t2down_C); } - displayText(t1up_C, t1down_C, digitalRead(PUMP1), t1up_C, t2down_C, digitalRead(PUMP2), - t1up(&t1up_C), t1down(&t1down_C), t2up(&t2up_C), t2down(&t2down_C)); + // write the infos to the display + displayText(t1up_C, t1down_C, digitalRead(PUMP1), t2up_C, t2down_C, digitalRead(PUMP2), + t1upState, t1downState, t2upState, t2downState); } diff --git a/solarpump/temperature.ino b/solarpump/temperature.ino index 9c3b9eec7cb8de9ea1667f42da42ff43731efc52..7b749e6df1197106ba4c2ca6b58383900396c338 100644 --- a/solarpump/temperature.ino +++ b/solarpump/temperature.ino @@ -1,4 +1,3 @@ -#include <stdint.h> #include "pins.h" #include <OneWire.h> #include <DallasTemperature.h>