2019-12-30 21:16:54 +00:00
|
|
|
#include "esphome.h"
|
|
|
|
|
2020-11-20 13:40:16 +00:00
|
|
|
using namespace esphome;
|
|
|
|
|
2019-12-30 21:16:54 +00:00
|
|
|
class BedSensor : public PollingComponent {
|
|
|
|
private:
|
|
|
|
const int melissaGpio = D0;
|
|
|
|
const int chrisGpio = D1;
|
|
|
|
const int sensorGpio = A0;
|
|
|
|
|
|
|
|
public:
|
2020-07-09 02:49:08 +00:00
|
|
|
Sensor *melissaBedSensor = new Sensor();
|
|
|
|
Sensor *chrisBedSensor = new Sensor();
|
2019-12-30 21:16:54 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-09 02:49:08 +00:00
|
|
|
melissaBedSensor->publish_state(melissaValue);
|
|
|
|
chrisBedSensor->publish_state(chrisValue);
|
2019-12-30 21:16:54 +00:00
|
|
|
}
|
|
|
|
};
|