implement button
This commit is contained in:
parent
67120c4c35
commit
a04958033e
@ -12,19 +12,43 @@
|
||||
|
||||
const char* FWNAME = "things@Sonoff";
|
||||
|
||||
bool state = LOW;
|
||||
bool switched = false;
|
||||
|
||||
const byte PIN_BUTTON = 0;
|
||||
|
||||
const byte PIN_RELAY = 12;
|
||||
DeviceRelay deviceRelay(PIN_RELAY, "relay");
|
||||
|
||||
const byte PIN_LED = 13;
|
||||
|
||||
Device* devices[] = {
|
||||
&deviceRelay,
|
||||
};
|
||||
|
||||
void hardwareSetup() {
|
||||
Homie.setLedPin(13, HIGH);
|
||||
Homie.setLedPin(PIN_LED, HIGH);
|
||||
pinMode(PIN_BUTTON, INPUT);
|
||||
pinMode(PIN_RELAY, OUTPUT);
|
||||
digitalWrite(PIN_RELAY, HIGH);
|
||||
};
|
||||
|
||||
void hardwareLoop() {};
|
||||
void hardwareLoop() {
|
||||
digitalWrite(PIN_LED, !state);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (digitalRead(PIN_BUTTON) == HIGH) {
|
||||
switched = false;
|
||||
return;
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
if (!switched) {
|
||||
state = !state;
|
||||
if (state) {
|
||||
deviceRelay.relayOnHandler("true");
|
||||
} else {
|
||||
deviceRelay.relayOnHandler("false");
|
||||
}
|
||||
switched = true;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user