Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
praktikaGruLa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Dominic Zahnd
praktikaGruLa
Commits
1939a37f
Commit
1939a37f
authored
1 year ago
by
Andreas Dominic Zahnd
Browse files
Options
Downloads
Patches
Plain Diff
uebung oop gelöst
parent
03708d30
Branches
main
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
w08-2024-ex1_flowerpots/src/Flowerpot.cpp
+49
-46
49 additions, 46 deletions
w08-2024-ex1_flowerpots/src/Flowerpot.cpp
w08-2024-ex1_flowerpots/src/Flowerpot.h
+23
-0
23 additions, 0 deletions
w08-2024-ex1_flowerpots/src/Flowerpot.h
with
72 additions
and
46 deletions
w08-2024-ex1_flowerpots/src/Flowerpot.cpp
+
49
−
46
View file @
1939a37f
...
...
@@ -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
},
moistureSensor
{
displayAddress
}
{}
// 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
::
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
::
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
::
observe
()
{
moisture
=
moistureSensor
.
getSoilMoisture
();
}
//
void Flowerpot::watering()
//
{
//
moisture = moistureSensor.watering();
//
}
void
Flowerpot
::
watering
()
{
moisture
=
moistureSensor
.
watering
();
}
This diff is collapsed.
Click to expand it.
w08-2024-ex1_flowerpots/src/Flowerpot.h
+
23
−
0
View file @
1939a37f
// Flowerpot.h
// TODO: Declare the Flowerpot class according to the class diagram here
#pragma once
#include
"MoistureSensor.h"
#include
<Servo.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
=
0
;
int
tickCount
=
0
;
int
valvePos
=
0
;
uint8_t
displayAddress
;
ValveStates
state
;
Servo
valve
;
MoistureSensor
moistureSensor
;
void
observe
();
void
watering
();
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment