Code: Select all
/ RELAY PINS:
#define RELAY_PIN_1 0
#define RELAY_PIN_2 1
#define RELAY_PIN_3 17
#define RELAY_PIN_4 18
#define RELAY_PIN_5 19
#define RELAY_PIN_6 20
#define RELAY_PIN_7 21
#define RELAY_PIN_8 7
#define RELAY_PIN_9 8
#define RELAY_PIN_10 9
#define RELAY_PIN_11 10
#define RELAY_PIN_12 11
#define RELAY_PIN_13 14
#define RELAY_PIN_14 15
#define RELAY_PIN_15 16
//saved states
byte curr_relay_states[15];
ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(get_relay_1,set_relay_1),
ZUNO_SWITCH_BINARY(get_relay_2,set_relay_2),
ZUNO_SWITCH_BINARY(get_relay_3,set_relay_3),
ZUNO_SWITCH_BINARY(get_relay_4,set_relay_4),
ZUNO_SWITCH_BINARY(get_relay_5,set_relay_5),
ZUNO_SWITCH_BINARY(get_relay_6,set_relay_6),
ZUNO_SWITCH_BINARY(get_relay_7,set_relay_7),
ZUNO_SWITCH_BINARY(get_relay_8,set_relay_8)
);
//zuno setup channels
void setup() {
/**
* Effectively just set all GPIOs to output
*/
pinMode(RELAY_PIN_1, OUTPUT);
pinMode(RELAY_PIN_2, OUTPUT);
pinMode(RELAY_PIN_3, OUTPUT);
pinMode(RELAY_PIN_4, OUTPUT);
pinMode(RELAY_PIN_5, OUTPUT);
pinMode(RELAY_PIN_6, OUTPUT);
pinMode(RELAY_PIN_7, OUTPUT);
pinMode(RELAY_PIN_8, OUTPUT);
pinMode(RELAY_PIN_9, OUTPUT);
pinMode(RELAY_PIN_10,OUTPUT);
pinMode(RELAY_PIN_11,OUTPUT);
pinMode(RELAY_PIN_12,OUTPUT);
pinMode(RELAY_PIN_13,OUTPUT);
pinMode(RELAY_PIN_14,OUTPUT);
pinMode(RELAY_PIN_15,OUTPUT);
set_relay_1(0);
set_relay_2(0);
set_relay_3(0);
set_relay_4(0);
set_relay_5(0);
set_relay_6(0);
set_relay_7(0);
set_relay_8(0);
set_relay_9(0);
set_relay_10(0);
set_relay_11(0);
set_relay_12(0);
set_relay_13(0);
set_relay_14(0);
set_relay_15(0);
}
void loop() {
}
// set state functions:
/*
* Set functions for the Z-Wave controller,
* Effectively, set HIGH when it should be off, and set 1 or zero (in this case zero is used) when the relay should be on/closed
*/
void set_relay_1(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_1, LOW);
else
digitalWrite (RELAY_PIN_1, HIGH);
curr_relay_states[0] = value;
}
void set_relay_2(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_2, LOW);
else
digitalWrite (RELAY_PIN_2, HIGH);
curr_relay_states[1] = value;
}
void set_relay_3(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_3, LOW);
else
digitalWrite (RELAY_PIN_3, HIGH);
curr_relay_states[2] = value;
}
void set_relay_4(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_4, LOW);
else
digitalWrite (RELAY_PIN_4, HIGH);
curr_relay_states[3] = value;
}
void set_relay_5(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_5, LOW);
else
digitalWrite (RELAY_PIN_5, HIGH);
curr_relay_states[4] = value;
}
void set_relay_6(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_6, LOW);
else
digitalWrite (RELAY_PIN_6, HIGH);
curr_relay_states[5] = value;
}
void set_relay_7(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_7, LOW);
else
digitalWrite (RELAY_PIN_7, HIGH);
curr_relay_states[6] = value;
}
void set_relay_8(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_8, LOW);
else
digitalWrite (RELAY_PIN_8, HIGH);
curr_relay_states[7] = value;
}
void set_relay_9(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_9, LOW);
else
digitalWrite (RELAY_PIN_9, HIGH);
curr_relay_states[8] = value;
}
void set_relay_10(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_10, LOW);
else
digitalWrite (RELAY_PIN_10, HIGH);
curr_relay_states[9] = value;
}
void set_relay_11(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_11, LOW);
else
digitalWrite (RELAY_PIN_11, HIGH);
curr_relay_states[10] = value;
}
void set_relay_12(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_12, LOW);
else
digitalWrite (RELAY_PIN_12, HIGH);
curr_relay_states[11] = value;
}
void set_relay_13(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_13, LOW);
else
digitalWrite (RELAY_PIN_13, HIGH);
curr_relay_states[12] = value;
}
void set_relay_14(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_14, LOW);
else
digitalWrite (RELAY_PIN_14, HIGH);
curr_relay_states[13] = value;
}
void set_relay_15(byte value)
{
if (value >0)
digitalWrite (RELAY_PIN_15, LOW);
else
digitalWrite (RELAY_PIN_15, HIGH);
curr_relay_states[14] = value;
}
// get state functions
/*
* Just retreves the current state and returns it to the Z-Wave Controller.
*/
byte get_relay_1() {return curr_relay_states[0];}
byte get_relay_2() {return curr_relay_states[1];}
byte get_relay_3() {return curr_relay_states[2];}
byte get_relay_4() {return curr_relay_states[3];}
byte get_relay_5() {return curr_relay_states[4];}
byte get_relay_6() {return curr_relay_states[5];}
byte get_relay_7() {return curr_relay_states[6];}
byte get_relay_8() {return curr_relay_states[7];}
byte get_relay_9() {return curr_relay_states[8];}
byte get_relay_10() {return curr_relay_states[9];}
byte get_relay_11() {return curr_relay_states[10];}
byte get_relay_12() {return curr_relay_states[11];}
byte get_relay_13() {return curr_relay_states[12];}
byte get_relay_14() {return curr_relay_states[13];}
byte get_relay_15() {return curr_relay_states[14];}