-
Notifications
You must be signed in to change notification settings - Fork 14
/
bed_sensor.h
34 lines (26 loc) · 835 Bytes
/
bed_sensor.h
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
#include "esphome.h"
using namespace esphome;
class BedSensor : public PollingComponent {
private:
const int melissaGpio = D0;
const int chrisGpio = D1;
const int sensorGpio = A0;
public:
Sensor *melissaBedSensor = new Sensor();
Sensor *chrisBedSensor = new Sensor();
BedSensor() : PollingComponent(5000) { }
void setup() override {
pinMode(melissaGpio, OUTPUT);
pinMode(chrisGpio, OUTPUT);
}
void update() override {
digitalWrite(melissaGpio, HIGH);
digitalWrite(chrisGpio, LOW);
int melissaValue = analogRead(sensorGpio);
digitalWrite(melissaGpio, LOW);
digitalWrite(chrisGpio, HIGH);
int chrisValue = analogRead(sensorGpio);
melissaBedSensor->publish_state(melissaValue);
chrisBedSensor->publish_state(chrisValue);
}
};