new device: pushbutton
This commit is contained in:
25
things/DeviceButton.cpp
Normal file
25
things/DeviceButton.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "DeviceButton.h"
|
||||
|
||||
void DeviceButton::deviceSetup() {
|
||||
pinMode(pin, INPUT);
|
||||
}
|
||||
|
||||
void DeviceButton::deviceRegister() {
|
||||
Homie.registerNode(buttonNode);
|
||||
}
|
||||
|
||||
void DeviceButton::deviceLoop() {
|
||||
byte debounce = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (digitalRead(pin) == state) {
|
||||
return;
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
state = !state;
|
||||
Serial.print("button: ");
|
||||
Serial.println(state);
|
||||
if (!Homie.setNodeProperty(buttonNode, "state", String(state), false)) {
|
||||
Serial.println("Sending failed");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user