Skip to content

Commit

Permalink
forgotten changes
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Dec 25, 2023
1 parent ce183b0 commit d299c43
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions controller/tea_poor/.gitignore
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
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 controller/tea_poor/lib/WaterPumpController/WaterPumpController.h
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

0 comments on commit d299c43

Please sign in to comment.