diff --git a/controller/tea_poor/.gitignore b/controller/tea_poor/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/controller/tea_poor/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp new file mode 100644 index 0000000..b8ce60f --- /dev/null +++ b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.cpp @@ -0,0 +1,38 @@ +#include +#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; +} diff --git a/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h new file mode 100644 index 0000000..8561876 --- /dev/null +++ b/controller/tea_poor/lib/WaterPumpController/WaterPumpController.h @@ -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