when I turn on a relay / button it does not return the correct state.
The script have 17 sub devices, could it be to large?
Temp sensors are retuning correct measurements.
But all the relays are not, I have configured to use puss-buttons.
Code: Select all
#include <ZUNO_MCP23017.h>
// MCP23017 Example: Slow key press reaction.
//
// Toggle LEDs and detect keypress.
// http://www.best-microcontroller-projects.com/mcp23017.html
// https://github.com/Z-Wave-Me/Z-Uno-Core/tree/master/hardware/examples
// Connect SCL to i2c clock - on Z-Uno thats Digital 9
// Connect SDA to i2c data - on Z-Uno thats Digital 10
// Connect pins #15, 16 and 17 of the expander to ground (address selection)
// Connect pin #9 of the expander to 5V (power)
// Connect pin #10 of the expander to ground (common ground)
// Connect pin #18 through a ~10kohm resistor to 5V (reset pin, active low)
#include <Wire.h>
#define MCP1_INPUTPIN0 0 //Sensor 0
#define MCP1_INPUTPIN1 1 //Sensor 1 (Garasje)
#define MCP1_INPUTPIN2 2 //Lys bryter 1
#define MCP1_INPUTPIN3 3 //Lys bryter 2
#define MCP1_INPUTPIN4 4 //Lys bryter 3
#define MCP1_INPUTPIN5 5 //Lys bryter 4
#define MCP1_INPUTPIN6 6 //Lys bryter 5
#define MCP1_INPUTPIN7 7 //Lys bryter 6
#define MCP1_INPUTPIN8 8 //Lys bryter 7 (Garasje)
#define MCP1_INPUTPIN9 9 //Røyk Sensor
#define MCP1_INPUTPIN10 10
#define MCP1_INPUTPIN11 11
#define MCP1_INPUTPIN12 12
#define MCP1_INPUTPIN13 13
#define MCP1_INPUTPIN14 14
#define MCP1_INPUTPIN15 15 //Disable Alarm Button
#define MCP2_OUTPUTPIN0 0
#define MCP2_OUTPUTPIN1 1
#define MCP2_OUTPUTPIN2 2 // Lys1
#define MCP2_OUTPUTPIN3 3 // Lys2
#define MCP2_OUTPUTPIN4 4 // Lys3
#define MCP2_OUTPUTPIN5 5 // Lys4
#define MCP2_OUTPUTPIN6 6 // Lys5
#define MCP2_OUTPUTPIN7 7 // Lys6
#define MCP2_OUTPUTPIN8 8 // Lys7 (Garasje)
#define MCP2_OUTPUTPIN9 9
#define MCP2_OUTPUTPIN10 10 //Gas
#define MCP2_OUTPUTPIN11 11 //Gas
#define MCP2_OUTPUTPIN12 12 //Avtrekksvifte
#define MCP2_OUTPUTPIN13 13
#define MCP2_OUTPUTPIN14 14 // Sirene
#define MCP2_OUTPUTPIN15 15 //LED Alarm status
#define Relay_PIN_1 19
unsigned long time = 0; // the last time the output pin was toggled
long debounce = 500; // the debounce time, increase if the output flickers
long debounce1 = 3000; // the debounce time, increase if the output flickers
int Sensor_0_State = 1; //Bevegelse Sensor
int Sensor_1_State = 1; //Bevegelse Sensor (Garasje)
int Button_2_State = 0; //Lys bryter 1
int Button_3_State = 0; //Lys bryter 2
int Button_4_State = 0; //Lys bryter 3
int Button_5_State = 0; //Lys bryter 4
int Button_6_State = 0; //Lys bryter 5
int Button_7_State = 0; //Lys bryter 6
int Button_8_State = 0; //Lys bryter 7 (Garasje)
int SmokeSensor_9_State = 0; //Røyk Sensor
int Button_10_State = 0; //Gas
int Button_11_State = 0; //Gas
int Button_12_State = 0;
int Button_13_State = 0;
int Button_14_State = 0;
int Button_15_State = 0; //Aktiver / Deaktiver Alarm
int Last_Sensor_0_State = 0;
int Last_Sensor_1_State = 0;
int Last_SmokeSensor_9_State = 0;
int AlarmOn = 0;
int AktiverSireneCount = 0;
int CurrentRelay_12_Value = 0; //Relay 1 Avtreksvifte
int CurrentRelay_14_Value = 0; //Relay 14 Alarm sirene
int Disable_Sensors = 1; //Disable sensor z wave traffic
int AlarmCount = 0;
ZUNO_MCP23017 mcp1;
ZUNO_MCP23017 mcp2;
#define addr1 0x00
#define addr2 0x01
#define addr3 0x02
int ledState = LOW;
long previousMillis = 0; // will store last time LED was updated
long OnTime = 1000; // milliseconds of on-time
long OffTime = 1000; // milliseconds of off-time
#define SWITCH_ON 255
#define SWITCH_OFF 0
//https://z-uno.z-wave.me/examples/1-wire-ds18b20-temperature-sensor/
/* koble 4,7K resistor mellom + og signal pinne 11 (gul)
* koble + og minus til 18B20 komponent flere i parralell
*/
// add library ds18b20
#include "ZUNO_DS18B20.h"
// pin connection ds18b20
#define DS18B20_BUS_PIN 11
#define N_SENSOR 2
OneWire ow(DS18B20_BUS_PIN);
// onewire connection temperature sensors
DS18B20Sensor ds1820(&ow);
#define ADDR_SIZE 8 // Size of address of devices on 1-wire bus
byte addresses[ADDR_SIZE * N_SENSOR];
#define ADDR(i) (&addresses[i * ADDR_SIZE]) // Macro to simplify our life
byte number_of_sensors; // Number of sensors found
word temperature[N_SENSOR]; // Here we store temperatures
long previousTempMillis = 0; // will store last time LED was updated
long TempDelayTime = 30000; // milliseconds of on-time
ZUNO_SETUP_DEBUG_MODE(DEBUG_OFF);
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);
ZUNO_SETUP_ASSOCIATIONS(ZUNO_ASSOCIATION_GROUP_SET_VALUE); // Send Basic Set to association group
ZUNO_SETUP_CHANNELS(//Max 32 enheter
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
getterTemp1),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_TEMPERATURE,
SENSOR_MULTILEVEL_SCALE_CELSIUS,
SENSOR_MULTILEVEL_SIZE_TWO_BYTES,
SENSOR_MULTILEVEL_PRECISION_TWO_DECIMALS,
getterTemp2),
ZUNO_SENSOR_BINARY_MOTION(getterSensor0), //Bevegelse Sensor 1
ZUNO_SENSOR_BINARY_MOTION(getterSensor1), //Bevegelse Sensor 2
ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch5, setterSwitch5), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch6, setterSwitch6), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch7, setterSwitch7), //Lysbryter
ZUNO_SWITCH_BINARY(getterSwitch8, setterSwitch8), //Lysbryter
ZUNO_SENSOR_BINARY_MOTION(getterSensor9), //Bevegelse Sensor 2
ZUNO_SWITCH_BINARY(getterSwitch10, setterSwitch10), //Releutgang Gass styring
ZUNO_SWITCH_BINARY(getterSwitch11, setterSwitch11), //Releutgang Gass styring
ZUNO_SWITCH_BINARY(getterSwitch12, setterSwitch12), //Releutgang Gass styring
ZUNO_SWITCH_BINARY(getterSwitch14, setterSwitch14), //Releutgang Gass styring
ZUNO_SWITCH_BINARY(getterSwitch15, setterSwitch15) //Alarm Bryter
);
void setup() {
Serial.begin(9600); // Initializes serial port
mcp1.begin(addr1); // Default device address 0
mcp1.pinMode(MCP1_INPUTPIN0,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN0,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN1,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN1,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN2,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN2,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN3,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN3,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN4,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN4,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN5,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN5,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN6,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN6,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN7,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN7,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN8,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN8,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN9,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN9,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN10,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN10,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN11,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN11,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN12,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN12,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN13,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN13,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN14,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN14,HIGH); // Puled high to ~100k
mcp1.pinMode(MCP1_INPUTPIN15,INPUT); // Button i/p to GND
mcp1.pullUp(MCP1_INPUTPIN15,HIGH); // Puled high to ~100k
mcp2.begin(addr2);
mcp2.pinMode(MCP2_OUTPUTPIN0,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN12,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN2,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN3,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN4,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN5,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN6,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN7,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN8,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN9,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN10,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN11,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN12,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN13,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN14,OUTPUT); // Output
mcp2.pinMode(MCP2_OUTPUTPIN15,OUTPUT); // Output
number_of_sensors = ds1820.findAllSensors(addresses); //Finn alle temp sensorer parralell koblet med 4,7K mellom signal og +5
}
void loop() {
//Start Temp Rutine
unsigned long currentTempMillis = millis();
if(currentTempMillis - previousTempMillis >= TempDelayTime){
previousTempMillis = currentTempMillis; // Remember the time
for (byte i = 0; i < number_of_sensors && i < N_SENSOR; i++) {
// Read temperature
temperature[i] = ds1820.getTemperature(ADDR(i)) * 100;
// Sending report
zunoSendReport(i + 1); // Channels starts from 10
Serial.println(temperature[i]);
}
}
//Slutt Temp Rutine
// Slå på Alarm, Led blinker i 25 sekunder før alarm er aktiv.
if ((AlarmCount > 10) && (AlarmCount < 50)) {
unsigned long currentMillis = millis();
if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
mcp2.digitalWrite(MCP2_OUTPUTPIN15, ledState); // Update the actual LED
AlarmCount = AlarmCount + 1;
Serial.println("AlarmLed Off");
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
mcp2.digitalWrite(MCP2_OUTPUTPIN15, ledState); // Update the actual LED
AlarmCount = AlarmCount + 1;
Serial.println("AlarmLed On");
}
if (AlarmCount == 50){
Disable_Sensors = 0;
Serial.println("Disable_Sensors = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN15, 1);
AlarmOn = 1;
zunoSendReport(17); // (må Endres)
}
}
if ((AktiverSireneCount > 10) && (AktiverSireneCount < 25)) {
unsigned long currentMillis = millis();
if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
mcp2.digitalWrite(MCP2_OUTPUTPIN15, ledState); // Update the actual LED
AktiverSireneCount = AktiverSireneCount + 1;
Serial.println("AlarmLed Off");
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
mcp2.digitalWrite(MCP2_OUTPUTPIN15, ledState); // Update the actual LED
AktiverSireneCount = AktiverSireneCount + 1;
Serial.println("AlarmLed On");
}
if (AktiverSireneCount == 25){
Serial.println("Sirene on");
mcp2.digitalWrite(MCP2_OUTPUTPIN14, 1);
setterSwitch14(255);
zunoSendReport(15);
}
}
if (AktiverSireneCount == 1) {
}
if (Disable_Sensors == 0) { //sjekker om sensorer er aktive / Disable Sensor Start
if (mcp1.digitalRead(MCP1_INPUTPIN0) != Last_Sensor_0_State && millis() - time > debounce1) {{ //Beveglese sensor 1
Serial.println("1. Sensor . ");
if (Sensor_0_State == 0) {
Sensor_0_State = 1;
Serial.println("Sensor 1.Bevegelse Ikke Aktiv");
zunoSendReport(3);
} else {
Sensor_0_State = 0;
Serial.println("Sensor 1.Bevegelse Aktiv");
zunoSendReport(3);
if ((AktiverSireneCount < 11) && (AktiverSireneCount != 25)){
AktiverSireneCount = 11;
}
}}
time = millis();
Last_Sensor_0_State = mcp1.digitalRead(MCP1_INPUTPIN0);
}
if (mcp1.digitalRead(MCP1_INPUTPIN1) != Last_Sensor_1_State && millis() - time > debounce1) {{ //Beveglese sensor 2
Serial.println("1. Sensor 2. ");
if (Sensor_1_State == 0) {
Sensor_1_State = 1;
Serial.println("Sensor 2.Bevegelse ikke Aktiv");
zunoSendReport(4);
} else {
Sensor_1_State = 0;
Serial.println("Sensor 2.Bevegelse Aktiv");
zunoSendReport(4);
if ((AktiverSireneCount < 11) && (AktiverSireneCount != 25)){
AktiverSireneCount = 11;
}
}}
time = millis();
Last_Sensor_1_State = mcp1.digitalRead(MCP1_INPUTPIN1);
}
}//Disable Sensor kontroll Slutt
if (mcp1.digitalRead(MCP1_INPUTPIN2)==0 && millis() - time > debounce) {{
if (Button_2_State == 0) {
Button_2_State = 1;
Serial.println("Button_2_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN2, HIGH);
zunoSendReport(5);
} else {
Button_2_State = 0;
Serial.println("Button_2_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN2, LOW);
zunoSendReport(5);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN3)==0 && millis() - time > debounce) {{
if (Button_3_State == 0) {
Button_3_State = 1;
Serial.println("Button_3_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN3, HIGH);
zunoSendReport(6);
} else {
Button_3_State = 0;
Serial.println("Button_3_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN3, LOW);
zunoSendReport(6);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN4)==0 && millis() - time > debounce) {{
if (Button_4_State == 0) {
Button_4_State = 1;
Serial.println("Button_4_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN4, HIGH);
zunoSendReport(7);
} else {
Button_4_State = 0;
Serial.println("Button_4_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN4, LOW);
zunoSendReport(7);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN5)==0 && millis() - time > debounce) {{
if (Button_5_State == 0) {
Button_5_State = 1;
Serial.println("Button_5_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN5, HIGH);
zunoSendReport(8);
} else {
Button_5_State = 0;
Serial.println("Button_5_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN5, LOW);
zunoSendReport(8);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN6)==0 && millis() - time > debounce) {{
if (Button_6_State == 0) {
Button_6_State = 1;
Serial.println("Button_6_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN6, HIGH);
zunoSendReport(9);
} else {
Button_6_State = 0;
Serial.println("Button_6_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN6, LOW);
zunoSendReport(9);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN7)==0 && millis() - time > debounce) {{
if (Button_7_State == 0) {
Button_7_State = 1;
Serial.println("Button_7_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN7, HIGH);
zunoSendReport(10);
} else {
Button_7_State = 0;
Serial.println("Button_7_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN7, LOW);
zunoSendReport(10);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN8)==0 && millis() - time > debounce) {{
if (Button_8_State == 0) {
Button_8_State = 1;
Serial.println("Button_8_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN8, HIGH);
zunoSendReport(11);
} else {
Button_8_State = 0;
Serial.println("Button_8_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN8, LOW);
zunoSendReport(11);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN9) != Last_SmokeSensor_9_State && millis() - time > debounce1) {{ //Røyk Sensor
Serial.println("Røyk Sensor endert status: ");
if (SmokeSensor_9_State == 0) {
SmokeSensor_9_State = 1;
Serial.println("Røyk Sensor .Ikke Aktiv");
zunoSendReport(12);
} else {
SmokeSensor_9_State = 0;
Serial.println("Røyk Sensor. Aktiv");
Serial.println("Sirene on");
mcp2.digitalWrite(MCP2_OUTPUTPIN14, 1);
setterSwitch14(255);
zunoSendReport(15);
zunoSendReport(12);
}}
time = millis();
Last_SmokeSensor_9_State = mcp1.digitalRead(MCP1_INPUTPIN9);
}
if (mcp1.digitalRead(MCP1_INPUTPIN10)==0 && millis() - time > debounce) {{
if (Button_10_State == 0) {
Button_10_State = 1;
Serial.println("Button_10_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN10, HIGH);
zunoSendReport(13);
} else {
Button_10_State = 0;
Serial.println("Button_10_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN10, LOW);
zunoSendReport(13);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN11)==0 && millis() - time > debounce) {{
if (Button_11_State == 0) {
Button_11_State = 1;
Serial.println("Button_11_State = 1");
mcp2.digitalWrite(MCP2_OUTPUTPIN11, HIGH);
zunoSendReport(14);
} else {
Button_11_State = 0;
Serial.println("Button_11_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN11, LOW);
zunoSendReport(14);
}}
time = millis();
}
if (mcp1.digitalRead(MCP1_INPUTPIN11)) {
} else {
// Serial.println("input11 = 0");
}
if (mcp1.digitalRead(MCP1_INPUTPIN12)) {
} else {
// Serial.println("input12 = 0");
}
if (mcp1.digitalRead(MCP1_INPUTPIN13)) {
} else {
// Serial.println("input13 = 0");
}
if (mcp1.digitalRead(MCP1_INPUTPIN14)) {
} else {
// Serial.println("input14 = 0");
}
if (mcp1.digitalRead(MCP1_INPUTPIN15)==0 && millis() - time > debounce) {{ //Alarm Aktivate /Deaktivate
Serial.println("1. Disable Alarm button 15. ");
if (Button_15_State == 0) {
Button_15_State = 1;
Serial.println("2. currentDisable_Alarm_State = 1");
AlarmCount = 11;
} else {
Button_15_State = 0;
Serial.println("3. currentDisable_Alarm_State = 0");
mcp2.digitalWrite(MCP2_OUTPUTPIN15, 0); // turn the LED off
AlarmOn = 0;
Disable_Sensors = 1;
AlarmCount = 1;
zunoSendReport(17); //sett Alarm status (må endres)
Sensor_0_State = 1;
zunoSendReport(3); //sett sensor status
Sensor_1_State = 1;
zunoSendReport(4); //sett sensor status
//zunoSendToGroupSetValueCommand(10, SWITCH_OFF);
//Reset alarm hvis utløst
AktiverSireneCount = 1;
setterSwitch14(0); //Sirene Rele
zunoSendReport(16); //Sirene Status (må endres)
}}
time = millis();
}
}
//Slutt på loop
int getterSensor0() { //Sender status til GW
if (Sensor_0_State == 0) { // if Sensor is triggerd
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
int getterSensor1() { //Sender status til GW
if (Sensor_1_State == 0) { // if Sensor is triggerd
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch2(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN2, 1); //turn the LED on (1 is the voltage level)
Button_2_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN2, 0); //turn the LED off by making the voltage 0
Button_2_State=0;
}
}
int getterSwitch2(){ //Sender status til GW
if (Button_2_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch3(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN3, 1); //turn the LED on (1 is the voltage level)
Button_3_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN3, 0); //turn the LED off by making the voltage 0
Button_3_State=0;
}
}
int getterSwitch3(){ //Sender status til GW
if (Button_3_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch4(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN4, 1); //turn the LED on (1 is the voltage level)
Button_4_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN4, 0); //turn the LED off by making the voltage 0
Button_4_State=0;
}
}
int getterSwitch4(){ //Sender status til GW
if (Button_4_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch5(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN5, 1); //turn the LED on (1 is the voltage level)
Button_5_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN5, 0); //turn the LED off by making the voltage 0
Button_5_State=0;
}
}
int getterSwitch5(){ //Sender status til GW
if (Button_5_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch6(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN6, 1); //turn the LED on (1 is the voltage level)
Button_6_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN6, 0); //turn the LED off by making the voltage 0
Button_6_State=0;
}
}
int getterSwitch6(){ //Sender status til GW
if (Button_6_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch7(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN7, 1); //turn the LED on (1 is the voltage level)
Button_7_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN7, 0); //turn the LED off by making the voltage 0
Button_7_State=0;
}
}
int getterSwitch7(){ //Sender status til GW
if (Button_7_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch8(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN8, 1); //turn the LED on (1 is the voltage level)
Button_8_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN8, 0); //turn the LED off by making the voltage 0
Button_8_State=0;
}
}
int getterSwitch8(){ //Sender status til GW
if (Button_8_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
int getterSensor9() { //Sender status til GW
if (SmokeSensor_9_State == 0) { // if Sensor is triggerd
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch10(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN10, 1); //turn the LED on (1 is the voltage level)
Button_10_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN10, 0); //turn the LED off by making the voltage 0
Button_10_State=0;
}
}
int getterSwitch10(){ //Sender status til GW
if (Button_10_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch11(int value) { //Bryter fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN11, 1); //turn the LED on (1 is the voltage level)
Button_11_State=1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN11, 0); //turn the LED off by making the voltage 0
Button_11_State=0;
}
}
int getterSwitch11(){ //Sender status til GW
if (Button_11_State == 1) { // if lys er på eller av
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch12(int value) { //Avtrekts vifte (pin12)
if (value > 0) { // if greater then zero
mcp2.digitalWrite(MCP2_OUTPUTPIN12, 1); //turn the LED on (1 is the voltage level)
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN12, 0); //turn the LED off by making the voltage 0
}
CurrentRelay_12_Value = value;
}
int getterSwitch12(){ //Sender status til GW
if (CurrentRelay_12_Value > 0) { // if Alarm are active or not
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch14(int value) { //Sirene
if (value > 0) { // if greater then zero
mcp2.digitalWrite(MCP2_OUTPUTPIN14, 1); //turn the LED on (1 is the voltage level)
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN14, 0); //turn the LED off by making the voltage 0
}
CurrentRelay_14_Value = value;
}
int getterSwitch14(){ //Sender status til GW
if (CurrentRelay_14_Value > 0) { // if Alarm are active or not
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
void setterSwitch15(int value) { //Alarm Aktivate /Deaktivate fra GW
if (value > 0) { // if greater then zero
mcp2.digitalWrite (MCP2_OUTPUTPIN15, 1); //turn the LED on (1 is the voltage level)
Disable_Sensors = 0;
AlarmCount = 50;
Button_15_State = 1;
AlarmOn = 1;
} else { // if equals zero
mcp2.digitalWrite(MCP2_OUTPUTPIN15, 0); //turn the LED off by making the voltage 0
Disable_Sensors = 1;
AlarmCount = 1;
Button_15_State = 0;
AlarmOn = 0;
AktiverSireneCount = 1;
}
}
int getterSwitch15(){ //Sender status til GW
if (AlarmOn == 1) { // if Alarm are active or not
return SWITCH_ON; // return "Triggered" state to the controller
} else { // if button is released
return SWITCH_OFF; // return "Idle" state to the controller
}
}
word getterTemp1() {
return temperature[0];
}
word getterTemp2() {
return temperature[1];
}