-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce183b0
commit d299c43
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
38 changes: 38 additions & 0 deletions
38
controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <Arduino.h> | ||
#include "WaterPumpController.h" | ||
|
||
WaterPumpController::WaterPumpController(int directionPin, int brakePin, int powerPin) : | ||
_directionPin(directionPin), | ||
_brakePin(brakePin), | ||
_powerPin(powerPin) | ||
{ | ||
|
||
} | ||
|
||
WaterPumpController::~WaterPumpController() {} | ||
|
||
void WaterPumpController::setup() { | ||
pinMode(_directionPin, OUTPUT); | ||
pinMode(_brakePin, OUTPUT); | ||
pinMode(_powerPin, OUTPUT); | ||
// TODO: check that its okay to do during setup | ||
stopPump(); | ||
} | ||
|
||
void WaterPumpController::pour(int milliseconds) { | ||
startPump(); | ||
delay(milliseconds); | ||
stopPump(); | ||
} | ||
|
||
void WaterPumpController::startPump() { | ||
_state = PUMP_ON; | ||
digitalWrite(_brakePin, LOW); // release breaks | ||
analogWrite(_powerPin, 255); | ||
} | ||
|
||
void WaterPumpController::stopPump() { | ||
digitalWrite(_brakePin, HIGH); // activate breaks | ||
analogWrite(_powerPin, 0); | ||
_state = PUMP_OFF; | ||
} |
28 changes: 28 additions & 0 deletions
28
controller/tea_poor/lib/WaterPumpController/WaterPumpController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef WATERPUMPCONTROLLER_H | ||
#define WATERPUMPCONTROLLER_H | ||
|
||
class WaterPumpController { | ||
public: | ||
enum EPumpState { | ||
PUMP_OFF, | ||
PUMP_ON | ||
}; | ||
private: | ||
const int _directionPin; | ||
const int _brakePin; | ||
const int _powerPin; | ||
const int _maxPower = 255; | ||
EPumpState _state = PUMP_OFF; | ||
public: | ||
WaterPumpController(int directionPin, int brakePin, int powerPin); | ||
~WaterPumpController(); | ||
|
||
void setup(); | ||
void pour(int miliseconds); | ||
void startPump(); | ||
void stopPump(); | ||
|
||
EPumpState state() const { return _state; } | ||
}; | ||
|
||
#endif // WATERPUMPCONTROLLER_H |