multiple sensors and vera

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
azvarga
Posts: 3
Joined: 24 Dec 2018 22:07

Re: multiple sensors and vera

Post by azvarga » 25 Dec 2018 06:56

Okay, figured it out. It was a matter of order of the code

Now working with 3 digital outputs and 6 digital inputs. LOVE the Z-Uno board !

Code: Select all

/* 
This sketch is used to interface the Genmon Raspberry Pi microprocessor to the Z-Uno Z-wave Arduino processor to provide a 
Z-wave interface between the generator and the VERA Plus home controller

                  PI     Z-Uno  
STATUS_READY      16      17  
STATUS_ALARM      18      18  
STATUS_SERVICE    22      19
STATUS_RUNNING    26      20  
STATUS_EXERCISING 24      21  
STATUS_OFF        21      22  
          
INPUT_STOP        11      9 
INPUT_START       13      10  
INPUT_TRANSFER    15      11  

Off - LOW
On - HIGH
*/

// Pin definitions

#define BINARY_PIN1 17
#define BINARY_PIN2 18
#define BINARY_PIN3 19
#define BINARY_PIN4 20
#define BINARY_PIN5 21 
#define BINARY_PIN6 22
#define LedPin1 9
#define LedPin2 10
#define LedPin3 11

// Global variables to store data reported via getters// Global variables to store data reported via getters

byte lastBinaryValue1;
byte lastBinaryValue2;
byte lastBinaryValue3;
byte lastBinaryValue4;
byte lastBinaryValue5;
byte lastBinaryValue6;
byte switchValue1 = 1;
byte switchValue2 = 1;
byte switchValue3 = 1;

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

// Send Basic Set to association group 

// ZUNO_SETUP_ASSOCIATIONS(ZUNO_ASSOCIATION_GROUP_SET_VALUE); 

// Set up 3 output channels and 5 input channels

ZUNO_SETUP_CHANNELS(
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary1),
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary2),
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary3),
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary4),
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary5),
  ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_MOTION, getterBinary6),  
  ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
  ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
  ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3)
);

// set up I/O pins. 

void setup() {
  pinMode(BINARY_PIN1, INPUT_PULLUP);
  pinMode(BINARY_PIN2, INPUT_PULLUP);
  pinMode(BINARY_PIN3, INPUT_PULLUP);
  pinMode(BINARY_PIN4, INPUT_PULLUP);
  pinMode(BINARY_PIN5, INPUT_PULLUP);
  pinMode(BINARY_PIN6, INPUT_PULLUP);
  pinMode(LedPin1, OUTPUT);
  pinMode(LedPin2, OUTPUT);
  pinMode(LedPin3, OUTPUT);
}

void loop() {
  byte currentBinaryValue1 = digitalRead(BINARY_PIN1);
  byte currentBinaryValue2 = digitalRead(BINARY_PIN2);
  byte currentBinaryValue3 = digitalRead(BINARY_PIN3);
  byte currentBinaryValue4 = digitalRead(BINARY_PIN4);
  byte currentBinaryValue5 = digitalRead(BINARY_PIN5);
  byte currentBinaryValue6 = digitalRead(BINARY_PIN6);

  if (currentBinaryValue1 != lastBinaryValue1) {
    lastBinaryValue1 = currentBinaryValue1;
    zunoSendReport(1);  
  }
  if (currentBinaryValue2 != lastBinaryValue2) {
    lastBinaryValue2 = currentBinaryValue2;
    zunoSendReport(2);  
  } 
  if (currentBinaryValue3 != lastBinaryValue3) {
    lastBinaryValue3 = currentBinaryValue3;
    zunoSendReport(3);  
  }
  if (currentBinaryValue4 != lastBinaryValue4) {
    lastBinaryValue4 = currentBinaryValue4;
    zunoSendReport(4);  
  }
  if (currentBinaryValue5 != lastBinaryValue5) {
    lastBinaryValue5 = currentBinaryValue5;
    zunoSendReport(5);  
  }
  if (currentBinaryValue6 != lastBinaryValue6) {
    lastBinaryValue6 = currentBinaryValue6;
    zunoSendReport(6);  
  }
}

// Getters

byte getterBinary1() {
    return (lastBinaryValue1 == 0) ? 0 : 255;
}
byte getterBinary2() {
    return (lastBinaryValue2 == 0) ? 0 : 255;
}
byte getterBinary3() {
    return (lastBinaryValue3 == 0) ? 0 : 255;
}
byte getterBinary4() {
    return (lastBinaryValue4 == 0) ? 0 : 255;
}
byte getterBinary5() {
    return (lastBinaryValue5 == 0) ? 0 : 255;
}
byte getterBinary6() {
    return (lastBinaryValue6 == 0) ? 0 : 255;
}

// Setters

void setterSwitch1(byte value) {
  digitalWrite(LedPin1, (value > 0) ? HIGH : LOW);
  switchValue1 = value;
}
byte getterSwitch1(){
  return switchValue1;
}
 void setterSwitch2(byte value) {
  digitalWrite(LedPin2, (value > 0) ? HIGH : LOW);
  switchValue2 = value;
}
byte getterSwitch2(){
  return switchValue2;
}
void setterSwitch3(byte value) {
  digitalWrite(LedPin3, (value > 0) ? HIGH : LOW);
  switchValue3 = value;
}
byte getterSwitch3(){
  return switchValue3;
}

Post Reply