SENSOR+SWITCH

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
lotes
Posts: 1
Joined: 25 Jun 2018 22:52

SENSOR+SWITCH

Post by lotes » 25 Jun 2018 23:05

Hi
I take code "SimpleSwitch" from example and add code from http://z-uno.z-wave.me/examples/SimpleSensor/
I'm add device at Fibaro HC2. The sensor and switch works, but when the switch is switched, the sensor state changes. I can't understand why this is happening. How can I break the connection between the switch and the sensor?

sketch, see below:

#define LED_PIN 13
#define BTN_PIN 18

#define ZUNO_CHANNEL_NUMBER_ONE 1

byte currentLEDValue;
byte lastButtonState;

ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getterSen),
ZUNO_SWITCH_BINARY(getterSw, setterSw)
);

void setup() {
pinMode(LED_PIN, OUTPUT); // set LED pin as output
pinMode(BTN_PIN, INPUT_PULLUP); // set button pin as input
}

void loop() {
byte currenButtonState = digitalRead(BTN_PIN);

if (currenButtonState != lastButtonState) {
lastButtonState = currenButtonState;
zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE);
}
}

byte getterSen() {
if (lastButtonState == 0) {
return 0xff;
} else {
return 0;
}
}

void setterSw (byte value) {
if (value > 0) {
digitalWrite (LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
currentLEDValue = value;
}

byte getterSw (){
return currentLEDValue;
}

Post Reply