-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDigitalSensor.h
90 lines (68 loc) · 1.63 KB
/
DigitalSensor.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
DigitalSensor - class describes
a set of methods for working with a digital sensor.
Instantiation:
Sensor* digitalSensor = new DigitalSensor(2);
Read signal:
int value = digitalSensor->read();
boolean value = digitalSensor->isHigh();
boolean value = digitalSensor->isLow();
v.1.3.3
Updated documentation.
v.1.3.4
Replaced "define" constants with "static const".
https://github.com/YuriiSalimov/AD_Sensors
Created by Yurii Salimov, May, 2018.
Released into the public domain.
*/
#ifndef DIGITAL_SENSOR_H
#define DIGITAL_SENSOR_H
#include "Sensor.h"
class DigitalSensor final : public Sensor {
private:
static const boolean DEFAULT_INVERT_SIGNAL = false;
int pin;
/**
Actuation signal.
If invert signal: signal = LOW
If not invert signal: signal = HIGH
*/
int signal;
public:
/**
Constructor
@param pin - a digital port number
that is attached to the sensor
@param invert - invert sensor signal (default, false)
*/
DigitalSensor(
int pin,
boolean invert = DEFAULT_INVERT_SIGNAL
);
/**
Reads and return a signal from the digital sensor,
from a digital port.
@return 0 or 1 (0 == LOW, 1 == HIGH)
*/
int read() override;
/**
Checks a signal on the digital sensor,
on the digital port.
@return true if the sensor signal is high,
false - otherwise
*/
boolean isHigh();
/**
Checks a signal on the digital sensor,
on the digital port.
@return true if the sensor signal is low,
false - otherwise
*/
boolean isLow();
/**
Inverts sensor signal.
@param invert - invert sensor signal
*/
void invertSignal(boolean invert);
};
#endif