File tree Expand file tree Collapse file tree 9 files changed +102
-10
lines changed
Expand file tree Collapse file tree 9 files changed +102
-10
lines changed Original file line number Diff line number Diff line change 11/*
2- Abstraction of a sensor .
2+ Abstraction of an actuator .
33*/
44
55#include " vor_actuator.h"
Original file line number Diff line number Diff line change 11/*
2- Button sensor.
2+ Digital button sensor.
33*/
44
55#include " vor_button.h"
Original file line number Diff line number Diff line change 11/*
2- Button sensor.
2+ Digital button sensor.
33*/
44
55#ifndef VOR_BUTTON_H
Original file line number Diff line number Diff line change 1+ /*
2+ Analog methane sensor.
3+ */
4+
5+ #include " vor_methane.h"
6+
7+ VorMethane::VorMethane (uint8_t pin) :
8+ VorSensor(pin, ANALOG_INPUT) {
9+
10+ }
11+
12+ float VorMethane::process (int value) {
13+ float volts = value / MAX_ANALOG_VALUE * MAX_VOLTS;
14+ // this equation was determined from a graph in datasheet, page 5:
15+ // https://cdn.sparkfun.com/datasheets/Sensors/Biometric/MQ-4%20Ver1.3%20-%20Manual.pdf
16+ float ppm = pow (M_E, (volts + 1.8992 ) / 0.619 );
17+ // float ppm = 23.953 * pow(M_E, 1.58 * volts); // alternative equation
18+ return ppm;
19+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Analog methane sensor.
3+ */
4+
5+ #ifndef VOR_METHANE_H
6+ #define VOR_METHANE_H
7+
8+ #include " env.h"
9+ #include " vor_sensor.h"
10+
11+ class VorMethane : public VorSensor {
12+ public:
13+ VorMethane (uint8_t pin);
14+
15+ float process (int value);
16+
17+ };
18+
19+ #endif
Original file line number Diff line number Diff line change 11/*
2- Button sensor.
2+ Digital PIR motion sensor.
33*/
44
55#include " vor_motion.h"
66
7- VorMotion::VorMotion (uint8_t pin) :
7+ VorMotion::VorMotion (uint8_t pin, uint32_t debounce ) :
88VorSensor(pin, DIGITAL_INPUT_PULLUP),
99_motionValue(HIGH),
10+ _debounce(debounce),
1011_debounceTime(0 ) {
1112
1213}
@@ -20,7 +21,7 @@ int VorMotion::read() {
2021 _debounceTime = now;
2122 }
2223
23- if (now - _debounceTime > DEBOUNCE ) {
24+ if (now - _debounceTime > _debounce ) {
2425 _motionValue = value;
2526 }
2627
Original file line number Diff line number Diff line change 11/*
2- PIR motion sensor.
2+ Digital PIR motion sensor.
33*/
44
55#ifndef VOR_MOTION_H
66#define VOR_MOTION_H
77
88#include " vor_sensor.h"
99
10- #define DEBOUNCE 30000 // milliseconds
11-
1210class VorMotion : public VorSensor {
1311public:
14- VorMotion (uint8_t pin);
12+ VorMotion (uint8_t pin, uint32_t debounce = 30000 );
1513
1614 int read ();
1715
16+ void setDebounce (uint32_t debounce) { _debounce = debounce; }
17+ uint32_t getDebounce () { return _debounce; }
18+
1819private:
1920
2021 int _motionValue;
22+ uint32_t _debounce;
2123 uint64_t _debounceTime; // milliseconds
2224
2325};
Original file line number Diff line number Diff line change 1+ /*
2+ Digital switch sensor.
3+ */
4+
5+ #include " vor_switch.h"
6+
7+ VorSwitch::VorSwitch (uint8_t pin) :
8+ VorSensor(pin, DIGITAL_INPUT),
9+ _debounceTime(0 ) {
10+
11+ }
12+
13+ int VorSwitch::read () {
14+ int value = VorSensor::read ();
15+ if (!_debounceTime) {
16+ _switchValue = value;
17+ }
18+ uint64_t now = millis ();
19+
20+ if (now - _debounceTime > DEBOUNCE && value != _switchValue) {
21+ _debounceTime = now;
22+ _switchValue = value;
23+ }
24+
25+ return _switchValue;
26+ }
Original file line number Diff line number Diff line change 1+ /*
2+ Digital switch sensor.
3+ */
4+
5+ #ifndef VOR_SWITCH_H
6+ #define VOR_SWITCH_H
7+
8+ #include " vor_sensor.h"
9+
10+ #define DEBOUNCE 100 // milliseconds
11+
12+ class VorSwitch : public VorSensor {
13+ public:
14+ VorSwitch (uint8_t pin);
15+
16+ int read ();
17+
18+ private:
19+
20+ int _switchValue;
21+ uint64_t _debounceTime; // milliseconds
22+
23+ };
24+
25+ #endif
You can’t perform that action at this time.
0 commit comments