-
Notifications
You must be signed in to change notification settings - Fork 1
/
Valve.cpp
58 lines (46 loc) · 1.48 KB
/
Valve.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "Valve.h"
#include "ExtendedIO.h"
// Constructor
Valve::Valve(int id, int pinPWM, int pinDigital)
: id(id), pinPWM(pinPWM), pinDigital(pinDigital), valveOpen(false) {
ExtendedIO::pinModeExtended(pinDigital, 1, 1);
}
// Getters
int Valve::getID() {
return this->id;
}
int Valve::getPinPWM() {
return this->pinPWM;
}
int Valve::getPinDigital() {
return this->pinDigital;
}
bool Valve::getValveOpen() {
return this->valveOpen;
}
// Setters
bool Valve::setPinDigital(int newPinDigital) {
this->pinDigital = newPinDigital;
if(this->pinDigital == newPinDigital){
return true;
}
return false;
}
bool Valve::setValveOpen(bool ValveOpenInput) {
/*Sets the state of Valve Objet: True (Open) | False (Close)
Returns true if successful*/
this->valveOpen = ValveOpenInput;
//ExtendedIO::pinModeExtended(this->pinDigital,1,1); // Sets Manual Pinmode to GPIO, Data Direction OUTPUT
pinMode(this->pinPWM,1);
if(ValveOpenInput == true){
ExtendedIO::digitalWriteExtended(this->pinDigital,1);
digitalWrite(this->pinPWM,1);
return true;
}
if(ValveOpenInput == false){
ExtendedIO::digitalWriteExtended(this->pinDigital,0);
digitalWrite(this->pinPWM,0);
return true;
}
return false;
}