Simple Sensor

That is a Simple Sensor Binary example. It watches over the built in button state and sends report to the controller if button's state changes. In this example we set up 1 sensor binary channel. Channel has one function:
  • getter — function, which returns the previously saved button state. This function runs only once the controller asks.
You can read more about this channel and his functions here.
  • Z-Uno board
  • Breadboard
            // LED pin number
// 13 pin - user LED of Z-Uno board
#define LED_PIN     13

// button pin number
// 18 pin - button(BTN) of Z-Uno board
#define BTN_PIN     18

// channel number
#define ZUNO_CHANNEL_NUMBER_ONE   1

// variable to store current button state
byte lastButtonState;

ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, getter));

// the setup routine runs once when you press reset:
void setup() {
  pinMode(LED_PIN, OUTPUT); // set LED pin as output
  pinMode(BTN_PIN, INPUT_PULLUP); // set button pin as input
}
// the loop routine runs over and over again forever:
void loop() {
  // sample current button state
  byte currenButtonState = digitalRead(BTN_PIN);

  if (currenButtonState != lastButtonState) { // if state changes
    lastButtonState = currenButtonState; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
    if (currenButtonState == LOW) { // if button is pressed
      digitalWrite(LED_PIN, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN, LOW);   // turn the LED off
    }
  }
}

byte getter() {
  if (lastButtonState == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}
        
    
  1. 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's not included in the network).
  2. Go to the Elements and here is your device — in this case (in sketch), you connected a Sensor Binary channel, so you see the Sensor General Purpose and its current status (on, off), which you can control by pressing tne button (if BTN is pressed - turn the LED on, if it's released - turn the LED off).