forked from vitotai/BrewPiLess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActuatorArduinoPin.h
54 lines (44 loc) · 959 Bytes
/
ActuatorArduinoPin.h
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
/*
* File: ArduinoActuator.h
* Author: mat
*
* Created on 19 August 2013, 20:32
*/
#pragma once
#include "Actuator.h"
template<uint8_t pin, bool invert>
class DigitalConstantPinActuator ACTUATOR_BASE_CLASS_DECL
{
private:
bool active;
public:
DigitalConstantPinActuator() : active(false)
{
setActive(false);
fastPinMode(pin, OUTPUT);
}
inline ACTUATOR_METHOD void setActive(bool active) {
this->active = active;
fastDigitalWrite(pin, active^invert ? HIGH : LOW);
}
bool isActive() { return active; }
};
class DigitalPinActuator ACTUATOR_BASE_CLASS_DECL
{
private:
bool invert;
uint8_t pin;
bool active;
public:
DigitalPinActuator(uint8_t pin, bool invert) {
this->invert = invert;
this->pin = pin;
setActive(false);
pinMode(pin, OUTPUT);
}
inline ACTUATOR_METHOD void setActive(bool active) {
this->active = active;
digitalWrite(pin, active^invert ? HIGH : LOW);
}
bool isActive() { return active; }
};