Skip to content

Commit faae2fc

Browse files
Add vor_methane and vor_switch.
1 parent c527180 commit faae2fc

File tree

9 files changed

+102
-10
lines changed

9 files changed

+102
-10
lines changed

vor-arduino/vor_actuator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Abstraction of a sensor.
2+
Abstraction of an actuator.
33
*/
44

55
#include "vor_actuator.h"

vor-arduino/vor_button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Button sensor.
2+
Digital button sensor.
33
*/
44

55
#include "vor_button.h"

vor-arduino/vor_button.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Button sensor.
2+
Digital button sensor.
33
*/
44

55
#ifndef VOR_BUTTON_H

vor-arduino/vor_methane.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

vor-arduino/vor_methane.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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

vor-arduino/vor_motion.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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) :
88
VorSensor(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

vor-arduino/vor_motion.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
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-
1210
class VorMotion : public VorSensor {
1311
public:
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+
1819
private:
1920

2021
int _motionValue;
22+
uint32_t _debounce;
2123
uint64_t _debounceTime; // milliseconds
2224

2325
};

vor-arduino/vor_switch.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

vor-arduino/vor_switch.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

0 commit comments

Comments
 (0)