Skip to content
Snippets Groups Projects
Commit 7097c0fb authored by Stefan Gehr's avatar Stefan Gehr
Browse files

code improvements

parent 8c74e55b
No related branches found
No related tags found
No related merge requests found
#include <Arduino.h>
#include "pins.h" #include "pins.h"
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
...@@ -17,7 +18,7 @@ void mp3Setup(void) { ...@@ -17,7 +18,7 @@ void mp3Setup(void) {
// immediately play a file // immediately play a file
void playFile(uint8_t fileNumber, bool respectBusyPin) { void playFile(uint8_t fileNumber, bool respectBusyPin) {
// do nothing if we want to wait for the BUSY pin // do nothing if we want to wait for the BUSY pin
if (respectBusyPin && digitalRead(MP3BUSY)) { if (respectBusyPin && digitalRead(MP3BUSY) == LOW) {
return; return;
} }
mp3.write(fileNumber); mp3.write(fileNumber);
......
#include <stdint.h> #include <Arduino.h>
#include "pins.h" #include "pins.h"
#include "temperature.h" #include "temperature.h"
#include "mp3.h" #include "mp3.h"
...@@ -154,29 +154,33 @@ void displayLight(bool turnOn) { ...@@ -154,29 +154,33 @@ void displayLight(bool turnOn) {
/* /*
* main setup function * main setup function
* initialize every electronic component * initialise every electronic component
*/ */
// main setup function
void setup(void) { void setup(void) {
lcd.init(); lcd.init();
Serial.begin(9600); // for debugging
// start the relevant libraries used by temperature.cpp // start the relevant libraries used by temperature.cpp
temperatureBegin(); temperatureBegin();
// start the mp3 library
mp3Setup(); mp3Setup();
// the pumps
pinMode(PUMP1, OUTPUT); pinMode(PUMP1, OUTPUT);
pinMode(PUMP2, OUTPUT); pinMode(PUMP2, OUTPUT);
// the button
pinMode(BUTTON, INPUT_PULLUP); pinMode(BUTTON, INPUT_PULLUP);
} }
// say out all the relevant infos via the loudspeaker // 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; const uint8_t decimals = 0;
// system 1
playFileQueue(SOUND_EINS); playFileQueue(SOUND_EINS);
// up temperature
playFileQueue(SOUND_OBEN); playFileQueue(SOUND_OBEN);
// say the number
sayNumber(temp1up, decimals); sayNumber(temp1up, decimals);
// wait a bit
playFileQueue(SOUND_STILLE); playFileQueue(SOUND_STILLE);
playFileQueue(SOUND_EINS); playFileQueue(SOUND_EINS);
...@@ -184,6 +188,15 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) ...@@ -184,6 +188,15 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down)
sayNumber(temp1down, decimals); sayNumber(temp1down, decimals);
playFileQueue(SOUND_STILLE); 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_ZWEI);
playFileQueue(SOUND_OBEN); playFileQueue(SOUND_OBEN);
sayNumber(temp2up, decimals); sayNumber(temp2up, decimals);
...@@ -194,34 +207,12 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down) ...@@ -194,34 +207,12 @@ void sayInfos(float temp1up, float temp1down, float temp2up, float temp2down)
sayNumber(temp2down, decimals); sayNumber(temp2down, decimals);
playFileQueue(SOUND_STILLE); 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_PUMPE);
playFileQueue(SOUND_ZWEI); playFileQueue(SOUND_ZWEI);
if (digitalRead(PUMP2)) {
playFileQueue(SOUND_AN); playFileQueue(SOUND_AN);
playFileQueue(SOUND_STILLE); } else {
}
else
{
playFileQueue(SOUND_PUMPE);
playFileQueue(SOUND_ZWEI);
playFileQueue(SOUND_AUS); playFileQueue(SOUND_AUS);
playFileQueue(SOUND_STILLE);
} }
} }
...@@ -247,21 +238,34 @@ void loop(void) { ...@@ -247,21 +238,34 @@ void loop(void) {
displayLight(false); displayLight(false);
} }
if (t1up(&t1up_C) == LONG_TIME_ERROR || t1down(&t1down_C) == LONG_TIME_ERROR) { // update the temperatures
// TODO: Warning sound 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 // Turn pump on to be safe
digitalWrite(PUMP1, HIGH); digitalWrite(PUMP1, HIGH);
} else { } else {
// no errors => control pump according to the temperatures
controlPump(PUMP1, t1up_C, t1down_C); controlPump(PUMP1, t1up_C, t1down_C);
} }
if (t2up(&t2up_C) == LONG_TIME_ERROR || t2down(&t2down_C) == LONG_TIME_ERROR) {
// TODO: Warning sound // same for system 2
// Turn pump on to be safe if (t2upState == LONG_TIME_ERROR || t2downState == LONG_TIME_ERROR) {
digitalWrite(PUMP2, HIGH); digitalWrite(PUMP2, HIGH);
} else { } else {
controlPump(PUMP2, t2up_C, t2down_C); controlPump(PUMP2, t2up_C, t2down_C);
} }
displayText(t1up_C, t1down_C, digitalRead(PUMP1), t1up_C, t2down_C, digitalRead(PUMP2), // write the infos to the display
t1up(&t1up_C), t1down(&t1down_C), t2up(&t2up_C), t2down(&t2down_C)); displayText(t1up_C, t1down_C, digitalRead(PUMP1), t2up_C, t2down_C, digitalRead(PUMP2),
t1upState, t1downState, t2upState, t2downState);
} }
#include <stdint.h>
#include "pins.h" #include "pins.h"
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment