Commit db026b9a authored by Toni Ruoss's avatar Toni Ruoss
Browse files

Uebung 6 vollständig

parent f5b76327
......@@ -5,6 +5,60 @@
#include <stdlib.h>
enum states
{
S_OBSERVE,
T_ENTERWATERING,
S_WATERING,
T_ENTEROBSERVE
};
Flowerpot::Flowerpot(int threshold, int panelMeterPin, Servo valve):threshold{threshold},panelMeterPin{panelMeterPin},valve{valve}
{
pinMode(panelMeterPin, OUTPUT);
valve.write(valvePos);
state = S_OBSERVE;
}
void Flowerpot::loop(){
switch (state)
{
case S_OBSERVE:
observe();
if (threshold > moisture){
state = T_ENTERWATERING;
}
break;
case T_ENTERWATERING:
valve.write(valvePos++);
if (valvePos > 90) {
state = S_WATERING;
}
break;
case S_WATERING:
watering();
tickCount++;
if (tickCount >=100){
tickCount = 0;
state = T_ENTEROBSERVE;
}
break;
case T_ENTEROBSERVE:
valve.write(valvePos--);
if(valvePos < 0){
state = S_OBSERVE;
}
break;
}
}
void Flowerpot::observe(){
moisture = moistureSensor.getSoilMoisture();
}
......@@ -14,12 +68,3 @@ void Flowerpot::watering()
moistureSensor.watering();
}
/*
void Flowerpot::loop(){
void Flowerpot.observe();
void Flowerpot.watering();
} */
\ No newline at end of file
// Flowerpot.h
#include "MoistureSensor.h"
#include "Servo.h"
#ifndef FLOWERPOT_H
#define FLOWERPOT_H
class Flowerpot
{
public:
MoistureSensor(int panelMeterPin);
void watering();
int getSoilMoisture();
Flowerpot(int threshold, int panelMeterPin, Servo valve);
void loop();
private:
void writeToPanel();
int soilMoisture{10};
int threshold;
int panelMeterPin;
int state;
int tickCount;
int valvePos{0};
int moisture{0};
MoistureSensor moistureSensor{panelMeterPin};
Servo valve;
void observe();
void watering();
};
#endif
\ No newline at end of file
......@@ -13,8 +13,8 @@ Servo valve1;
Servo valve2;
Servo valve3;
Flowerpot flowerpot1{10, METER_PIN1, valve1};
Flowerpot flowerpot2{50, METER_PIN2, valve2};
Flowerpot flowerpot1{10, METER_PIN1, valve1}; //threshold, panelMeterPin, valve
Flowerpot flowerpot2{50, METER_PIN2, valve2}; //threshold = Feuchtigkeitswert (unterschiedlich für verschiedene Pflanzen)
Flowerpot flowerpot3{30, METER_PIN3, valve3};
void setup() {
......
// Flowerpot.cpp
void Flowerpot::observe(){
moisture = moistureSensor.getSoilMoisture();
}
void Flowerpot::watering()
{
moistureSensor.watering();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment