Hi,
new to the forum and Arduino and loving playing with the new gadget!
I'm integrating my alarm system with my z-wave (Domitcz) network and need to setup some logic which will latch based on inputs.
I have only two outputs and 4 inputs, so I'm translating this to a binary number to get the count high enough.
I need it to latch as it seems if a statement == true on a loop it keeps switching, which kills my zwave device..
Code below, the issue is it that the final 4 if statements dont work. In the serial port I see a constant stream of 'A off' 'B off' etc etc, instead of a final 'A off statement'.
Any ideas?
Thanks
//www.elegoo.com
//2016.12.08
// Setup output pins for z-wave :
int fibPin1 = 2;
int fibPin2 = 3;
// Setup input pins for 4 alarm types :
int buttonApin = 8;
int buttonBpin = 9;
int buttonCpin = 10;
int buttonDpin = 11;
// Setup variable to remember current status :
int inputVariable = 0;
void setup()
{
pinMode(fibPin1, OUTPUT);
pinMode(fibPin2, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
pinMode(buttonCpin, INPUT_PULLUP);
pinMode(buttonDpin, INPUT_PULLUP);
Serial.begin(9600);
while (! Serial); // Wait untilSerial is ready - Leonardo
digitalWrite(fibPin1, HIGH);
digitalWrite(fibPin2, HIGH);
}
void loop()
{
// If input 1 active, write binary 00 :
if ((digitalRead(buttonApin) == LOW) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable != 1))
{
digitalWrite(fibPin1, LOW);
digitalWrite(fibPin2, LOW);
Serial.print("A on");
Serial.println();
inputVariable = 1;
}
// If input 2 active, write binary 01 :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == LOW) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable != 2))
{
digitalWrite(fibPin1, LOW);
digitalWrite(fibPin2, HIGH);
Serial.print("B on");
Serial.println();
inputVariable = 2;
}
// If input 3 active, write binary 10 :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == LOW) && (digitalRead(buttonDpin) == HIGH) && (inputVariable != 3))
{
digitalWrite(fibPin1, HIGH);
digitalWrite(fibPin2, LOW);
Serial.print("C on");
Serial.println();
inputVariable = 3;
}
// If input 4 active, write binary 11 :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == LOW) && (inputVariable != 4))
{
digitalWrite(fibPin1, HIGH);
digitalWrite(fibPin2, HIGH);
Serial.print("D on");
Serial.println();
inputVariable = 4;
}
// If input 1 no longer active, write binary 00 AND stop until change :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable = 1))
{
digitalWrite(fibPin1, LOW);
digitalWrite(fibPin2, LOW);
inputVariable = 0;
Serial.print("A off");
Serial.print(inputVariable);
Serial.println();
}
// If input 2 no longer active, write binary 00 AND stop until change :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable = 2))
{
digitalWrite(fibPin1, LOW);
digitalWrite(fibPin2, HIGH);
inputVariable = 0;
Serial.print("B off");
Serial.print(inputVariable);
Serial.println();
}
// If input 3 no longer active, write binary 00 AND stop until change :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable = 3))
{
digitalWrite(fibPin1, HIGH);
digitalWrite(fibPin2, LOW);
inputVariable = 0;
Serial.print("C off");
Serial.print(inputVariable);
Serial.println();
}
// If input 4 no longer active, write binary 00 AND stop until change :
if ((digitalRead(buttonApin) == HIGH) && (digitalRead(buttonBpin) == HIGH) && (digitalRead(buttonCpin) == HIGH) && (digitalRead(buttonDpin) == HIGH) && (inputVariable = 4))
{
digitalWrite(fibPin1, HIGH);
digitalWrite(fibPin2, HIGH);
inputVariable = 0;
Serial.print("D off");
Serial.print(inputVariable);
Serial.println();
}
}