-
Notifications
You must be signed in to change notification settings - Fork 9
/
AnalogSensor.cpp
41 lines (37 loc) · 887 Bytes
/
AnalogSensor.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
#include "AnalogSensor.h"
AnalogSensor::AnalogSensor(int pn, int p, int sid, byte type, int f) : BaseSensor(p,sid,f)
{
pin = pn;
Type = type;
}
void AnalogSensor::Begin(byte i)
{
BaseSensor::Begin(i);
readCounter = 0;
sensorValue = 0;
sensorIsOn = false;
}
void AnalogSensor::CheckSensor()
{
// read the analog input 10 times before evaluating
sensorValue += analogRead(pin);
readCounter++;
if(readCounter == 10)
{
// rising edge?
if(sensorValue > TH && sensorIsOn == false)
{
pulseLength = millis() - lastMillis;
lastMillis = millis();
todayCnt++;
sensorIsOn = true;
}
// falling edge?
if(sensorValue < TL && sensorIsOn == true)
{
sensorIsOn = false;
}
readCounter = 0;
sensorValue = 0;
}
}