-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorTool.cpp
More file actions
49 lines (44 loc) · 803 Bytes
/
SensorTool.cpp
File metadata and controls
49 lines (44 loc) · 803 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
49
#include "SensorTool.h"
Sensor::Sensor(int _SensorPin, Type _type)
{
SensorPin = _SensorPin;
SensorType = _type;
PreviousValue = 0;
}
int Sensor::Read()
{
switch (SensorType)
{
case Analog:
{
int Value = analogRead(SensorPin);
return Value;
}
case Digital:
{
pinMode(SensorPin, INPUT);
int Value = digitalRead(SensorPin);
return Value;
}
}
}
int Sensor::DetectChange()
{
int Value = Read();
if (PreviousValue != Value)
{
PreviousValue = Value;
return PreviousValue;
}
return 0;
}
String Sensor::toString() //FOR DEBUG USE ONLY! PRINTS TO SERIAL MONITOR
{
String _type;
Serial.print("Sensor Pin: ");
Serial.println(SensorPin);
if (SensorType == Analog) _type = "Analog";
else _type = "Digital";
Serial.print("Sensor Type: ");
Serial.println(_type);
}