Simple Switch
In this example we set up 1 Switch Binary channel.
Channel has two functions:
- setter — function, which sets new relay state. This function runs only once the controller sends new value.
- getter — function, which returns the previously saved relay value. This function runs only once the controller asks.
You can read more about this channel and his functions here.
// LED pin number
// 13 pin - user LED of Z-Uno board
#define LED_PIN 13
// Last saved LED value
byte currentLEDValue;
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));
// the setup routine runs once when you press reset:
void setup() {
pinMode(LED_PIN, OUTPUT); // setup pin as output
}
// the loop routine runs over and over again forever:
void loop() {
// loop is empty, because all the control comes over the Z-Wave
}
void setter(byte value) {
// value is a variable, holding a "new value"
// which came from the controller or other Z-Wave device
if (value > 0) { // if greater then zero
digitalWrite (LED_PIN, HIGH); //turn the LED on (HIGH is the voltage level)
} else { // if equals zero
digitalWrite(LED_PIN, LOW); //turn the LED off by making the voltage LOW
}
// we'll save our value for the situation, when the controller will ask us about it
currentLEDValue = value;
}
byte getter() {
return currentLEDValue;
}
- Include Z-Uno into a network (if you do it the first time) or Exclude again (also by pressing the button three times), and then again Include (it will be useful if you already included the device, or just to check if it is not included in the network).
- Go to the Elements and here is your device — in this case (in sketch) , you connected a Switch Binary channel, so you see the Switch and its current status (on / off), which you can control from here, by clicking ON you turn the LED on the board
It's a kind of magic! Your device is done and it's working! Congratulations!