-
Notifications
You must be signed in to change notification settings - Fork 0
/
4chpro-fan.h
33 lines (31 loc) · 860 Bytes
/
4chpro-fan.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
#include "esphome.h"
using namespace esphome;
#define PIN_1 12
#define PIN_2 5
#define PIN_3 4
class Sonoff4CHProFan : public Component, public FloatOutput {
public:
void write_state(float state) override {
if (state < 0.3) {
// OFF
digitalWrite(PIN_1, LOW);
digitalWrite(PIN_2, LOW);
digitalWrite(PIN_3, LOW);
} else if (state < 0.6) {
// low speed
digitalWrite(PIN_1, HIGH);
digitalWrite(PIN_2, LOW);
digitalWrite(PIN_3, LOW);
} else if (state < 0.9) {
// medium speed
digitalWrite(PIN_1, LOW);
digitalWrite(PIN_2, HIGH);
digitalWrite(PIN_3, LOW);
} else {
// high speed
digitalWrite(PIN_1, LOW);
digitalWrite(PIN_2, LOW);
digitalWrite(PIN_3, HIGH);
}
}
};