-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopHandlerSensor.cpp
More file actions
37 lines (32 loc) · 1.08 KB
/
Copy pathLoopHandlerSensor.cpp
File metadata and controls
37 lines (32 loc) · 1.08 KB
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
#include "LoopHandlerSensor.hpp"
#include "GroupBundle.hpp"
#define SENSOR_PIN_INPUT 3
#define SENSOR_PIN_OUTPUT 14
#define SENSOR_THRESHOLD 7000
#define SENSOR_DELAY 600
LoopHandlerSensor::LoopHandlerSensor(GroupBundle* bundle, bool debugOutput) : LoopHandler(bundle, debugOutput), m_sensor(SENSOR_PIN_OUTPUT, SENSOR_PIN_INPUT), m_previousMillis(0) {
// disable auto calibration
m_sensor.set_CS_AutocaL_Millis(0xFFFFFFFF);
}
void LoopHandlerSensor::loopInternal() {
// measure capacitive sensor
long measurement = m_sensor.capacitiveSensor(30);
// check the capacitive sensor
if (m_previousMillis == 0 && measurement > SENSOR_THRESHOLD) {
// keep milliseconds
m_previousMillis = millis();
if (m_debugOutput) {
Serial.println(String(measurement));
}
// toggle group
m_bundle->toggle(43);
}
// check whether to reset after delay
if (m_previousMillis > 0 && millis() - m_previousMillis > SENSOR_DELAY) {
digitalWrite(SENSOR_PIN_INPUT, LOW);
m_previousMillis = 0;
if (m_debugOutput) {
Serial.println(F("RESET!"));
}
}
}