25 lines
		
	
	
		
			495 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			495 B
		
	
	
	
		
			C++
		
	
	
	
	
	
#include "DeviceButton.h"
 | 
						|
 | 
						|
void DeviceButton::deviceSetup() {
 | 
						|
  pinMode(pin, INPUT);
 | 
						|
}
 | 
						|
 | 
						|
void DeviceButton::deviceRegister() {
 | 
						|
  Homie.registerNode(buttonNode);
 | 
						|
}
 | 
						|
 | 
						|
void DeviceButton::deviceLoop() {
 | 
						|
  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");
 | 
						|
  }
 | 
						|
}
 |