ESPHome-Devices/custom/bed_sensor.h
2020-11-20 07:40:16 -06:00

34 lines
835 B
C++

#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);
}
};