|
|
@ -24,8 +24,10 @@ |
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <SparkFun_MicroPressure.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
|
|
|
|
SparkFun_MicroPressure mpr; |
|
|
|
LiquidCrystal_I2C lcdDisplay = LiquidCrystal_I2C(0x27, 16, 2); |
|
|
|
|
|
|
|
// Zuordnung der Ein- Ausgänge
|
|
|
|
#define VENTIL 5 // GPIO5 (PWM MotorA)
|
|
|
@ -49,6 +51,33 @@ int atmDruck = 97400; |
|
|
|
* HELPERS FOR INPUT / OUTPUT |
|
|
|
*/ |
|
|
|
|
|
|
|
void initDisplay() { |
|
|
|
lcdDisplay.display(); |
|
|
|
lcdDisplay.noBlink(); |
|
|
|
lcdDisplay.noCursor(); |
|
|
|
lcdDisplay.clear(); |
|
|
|
lcdDisplay.backlight(); |
|
|
|
} |
|
|
|
|
|
|
|
void disableDisplay() { |
|
|
|
lcdDisplay.noDisplay(); |
|
|
|
} |
|
|
|
|
|
|
|
void printMsgToLCD(const String& line_one, const String& line_two) { |
|
|
|
lcdDisplay.clear(); |
|
|
|
lcdDisplay.setCursor(0, 0); |
|
|
|
lcdDisplay.print(line_one); |
|
|
|
lcdDisplay.setCursor(0, 1); |
|
|
|
lcdDisplay.print(line_two); |
|
|
|
} |
|
|
|
|
|
|
|
void printDebugMsg(const String& type, const String& msg) { |
|
|
|
if (Serial.available()) { |
|
|
|
Serial.println(type + msg); |
|
|
|
} |
|
|
|
printMsgToLCD(type, msg); |
|
|
|
} |
|
|
|
|
|
|
|
void printMeasurements(const int& pressure) { |
|
|
|
const int wassersaeule = convertPressureToHeight(currentPressure); |
|
|
|
|
|
|
@ -62,6 +91,8 @@ void printMeasurements(const int& pressure) { |
|
|
|
Serial.println("Volumen: " + volumen); |
|
|
|
Serial.println("Füllstand: " + fuellstand); |
|
|
|
} |
|
|
|
|
|
|
|
printMsgToLCD("Vol: " + volumen, "Stand: " + fuellstand); |
|
|
|
} |
|
|
|
|
|
|
|
void handleSerialInput() { |
|
|
@ -140,6 +171,9 @@ int setAtmosphericPressure() { |
|
|
|
*/ |
|
|
|
|
|
|
|
void Measurement() { |
|
|
|
initDisplay(); |
|
|
|
printDebugMsg("Info: ", "Messung begonnen"); |
|
|
|
|
|
|
|
int oldPressure = getPressureSensorValue(); |
|
|
|
digitalWrite(VENTIL, ZU); |
|
|
|
digitalWrite(PUMPE, EIN); |
|
|
@ -151,8 +185,8 @@ void Measurement() { |
|
|
|
if (convertPressureToHeight(currentPressure) > (maxFuellhoehe + 200)) { |
|
|
|
digitalWrite(VENTIL, AUF); |
|
|
|
digitalWrite(PUMPE, AUS); |
|
|
|
Serial.println("Fehler: Messleitung verstopft!"); |
|
|
|
return; |
|
|
|
printDebugMsg("Fehler: ", "Leitung verstopft"); |
|
|
|
while(1); |
|
|
|
} |
|
|
|
|
|
|
|
if (currentPressure > oldPressure + 10) { |
|
|
@ -170,6 +204,8 @@ void Measurement() { |
|
|
|
digitalWrite(PUMPE, AUS); |
|
|
|
|
|
|
|
printMeasurements(finalPressure); |
|
|
|
delay(5000); |
|
|
|
disableDisplay(); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -177,6 +213,8 @@ void Measurement() { |
|
|
|
*/ |
|
|
|
|
|
|
|
void setup() { |
|
|
|
printDebugMsg("") |
|
|
|
|
|
|
|
// Richtung Motor A
|
|
|
|
pinMode(DA, OUTPUT); |
|
|
|
digitalWrite(DA, HIGH); |
|
|
@ -201,9 +239,17 @@ void setup() { |
|
|
|
// Die Default-Adresse des Sensors ist 0x18
|
|
|
|
// Für andere Adresse oder I2C-Bus: mpr.begin(ADRESS, Wire1)
|
|
|
|
if(!mpr.begin()) { |
|
|
|
Serial.println("Keine Verbindung zum Drucksensor."); |
|
|
|
printDebugMsg("Fehler: ", "Drucksensor"); |
|
|
|
while(1); |
|
|
|
} |
|
|
|
|
|
|
|
// Display initialisieren
|
|
|
|
lcdDisplay.init(); |
|
|
|
|
|
|
|
initDisplay(); |
|
|
|
printDebugMsg("Info: ", "Geladen"); |
|
|
|
delay(1000); |
|
|
|
disableDisplay(); |
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|