-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelay.cpp
More file actions
48 lines (39 loc) · 807 Bytes
/
Relay.cpp
File metadata and controls
48 lines (39 loc) · 807 Bytes
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
/*
* Relay.cpp
*
* Created on: Sep 10, 2012
* Author: sfeltner
*/
#include "Relay.h"
Relay::Relay(uint8_t pin, bool startState) {
_pin = pin;
_state = startState;
pinMode(_pin, OUTPUT);
if(startState)
digitalWrite(_pin, LOW);
else
digitalWrite(_pin, HIGH);
}
Relay::~Relay() {
// TODO Auto-generated destructor stub
}
//Returns false if it does NOT perform a state change
bool Relay::SetState(bool newState){
if(_state == newState)
return false;
else if(newState){
_state = true;
digitalWrite(_pin, LOW);
return true;
}
else if(!newState){
_state = false;
digitalWrite(_pin, HIGH);
return true;
}
return false;
}
//Returns false if it does NOT perform a state change
bool Relay::GetState(){
return _state;
}