Skip to content
Snippets Groups Projects
Commit 417f7124 authored by Roman Jan Ernst's avatar Roman Jan Ernst
Browse files

Lernen Prüfung 2.2

parent b61ace4e
No related branches found
No related tags found
No related merge requests found
<diagram program="umletino" version="15.1"><zoom_level>10</zoom_level><element><id>UMLClass</id><coordinates><x>50</x><y>120</y><w>210</w><h>190</h></coordinates><panel_attributes>Fahrzeug
--
-farbe : string
- kilometerStand : int
--
+ fahren(): void
+ lenken(winkel int): void
+istTuerOffen(): bool
+getFarbe(): String
+getKilometerstand(): int
</panel_attributes><additional_attributes></additional_attributes></element></diagram>
\ No newline at end of file
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
{
"C_Cpp_Runner.cCompilerPath": "C:/Users/ernst/.platformio/packages/toolchain-atmelavr/bin/avr-gcc.exe",
"C_Cpp_Runner.cppCompilerPath": "C:/Users/ernst/.platformio/packages/toolchain-atmelavr/bin/avr-g++.exe",
"C_Cpp_Runner.debuggerPath": "C:/Users/ernst/.platformio/packages/toolchain-atmelavr/bin/avr-gdb.exe",
"C_Cpp_Runner.cStandard": "gnu11",
"C_Cpp_Runner.cppStandard": "gnu++11",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [
"C:/Users/ernst/respitories/praktika-grulait/w08-2024-ex1_flowerpots_2.0/src",
"C:/Users/ernst/respitories/praktika-grulait/w08-2024-ex1_flowerpots_2.0/.pio/libdeps/uno/LiquidCrystal_AIP31068",
"C:/Users/ernst/respitories/praktika-grulait/w08-2024-ex1_flowerpots_2.0/.pio/libdeps/uno/SoftSPIB",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
"C:/Users/ernst/respitories/praktika-grulait/w08-2024-ex1_flowerpots_2.0/.pio/libdeps/uno/Servo/src",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/cores/arduino",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/variants/standard",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/libraries/HID/src",
"C:/Users/ernst/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
""
],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
\ No newline at end of file
......@@ -4,55 +4,58 @@
#include "Flowerpot.h"
// TODO: Implement the constructor
Flowerpot::Flowerpot(int threshold, uint8_t displayAddress, int valvePin)
: threshold{threshold}, displayAddress{displayAddress}, valvePin{valvePin},
moisture{0},tickCount{0}, valvePos{0},
moistureSensor{displayAddress}
{
state = S_OBSERVE;
};
// TODO: Uncomment the following code. begin(), loop(), observe(), and watering() are already implemented
// void Flowerpot::begin()
// {
// moistureSensor.begin();
// valve.attach(valvePin, 1000, 2000);
// valve.write(valvePos);
// }
// 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();
// }
// void Flowerpot::watering()
// {
// moisture = moistureSensor.watering();
// }
//TODO: Uncomment the following code. begin(), loop(), observe(), and watering() are already implemented
void Flowerpot::begin()
{
moistureSensor.begin();
valve.attach(valvePin, 1000, 2000);
valve.write(valvePos);
}
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();
}
void Flowerpot::watering()
{
moisture = moistureSensor.watering();
}
// Flowerpot.h
// TODO: Declare the Flowerpot class according to the class diagram here
#pragma once
#include <Servo.h>
#include "MoistureSensor.h"
class Flowerpot{
public:
Flowerpot(int threshold, uint8_t displayAddress, int valvePin);
void begin();
void loop();
private:
enum ValveStates{S_OBSERVE, T_ENTERWATERING, S_WATERING, T_ENTEROBSERVE};
int threshold;
int valvePin;
int moisture;
int tickCount;
int valvePos;
uint8_t displayAddress;
ValveStates state;
MoistureSensor moistureSensor;
Servo valve;
void observe();
void watering();
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment