So I am trying to do this step by step.
I am trying to read tstatValue1 when HIGH for example and have it turn on zone1 for a half of second and then off while the tstatValue1 is still HIGH. Then when tstatValue1 changes back to LOW zone1 is still LOW and waiting to turn on again. Now to make it fun zonereverse1 is doing exactly opposite zone1. I will then replicate that across 4 independent inputs.
The thing I am trying to do with code. zone 2,3,4 was just me trying to see if I could get it to work without the half second turn off hence why it is commented out:
const int zone1 = 1;
const int zone2 = 2;
const int zone3 = 3;
const int zone4 = 4;
const int zonereverse1 = 5;
const int zonereverse2 = 6;
const int zonereverse3 = 7;
const int zonereverse4 = 8;
const int tstat1 = A0;
const int tstat2 = A1;
const int tstat3 = A2;
const int tstat4 = A3;
int tstatValue1 = LOW;
int tstatValue2 = LOW;
int tstatValue3 = LOW;
int tstatValue4 = LOW;
int tstatState1 = LOW;
int tstatState2 = LOW;
int tstatState3 = LOW;
int tstatState4 = LOW;void setup ()
{
pinMode(tstat1, INPUT);
pinMode(tstat2, INPUT);
pinMode(tstat3, INPUT);
pinMode(tstat4, INPUT);
digitalWrite(tstat1,HIGH);
digitalWrite(tstat2,HIGH);
digitalWrite(tstat3,HIGH);
digitalWrite(tstat4,HIGH);
pinMode(zone1, OUTPUT);
pinMode(zone2, OUTPUT);
pinMode(zone3, OUTPUT);
pinMode(zone4, OUTPUT);
pinMode(zonereverse1, OUTPUT);
pinMode(zonereverse2, OUTPUT);
pinMode(zonereverse3, OUTPUT);
pinMode(zonereverse4, OUTPUT);
}void loop ()
{
tstatValue1 = digitalRead(tstat1);
delay(50);//tstatValue2 = digitalRead(tstat2);
//tstatValue3 = digitalRead(tstat3);
//tstatValue4 = digitalRead(tstat4);
if (tstatValue1 == HIGH && tstatState1 == LOW)
{
digitalWrite(zone1,HIGH); // relay1 is power-on
digitalWrite(zonereverse1,LOW); // relay5 is power-off
delay(500); //half-second close
digitalWrite(zone1,LOW); // relay1 is powered-off
digitalWrite(zonereverse1,HIGH); // relay5 is power-on
delay(500); //half-second close
digitalWrite(zonereverse1,LOW); // relay5 is power-off
tstatState1 = HIGH;
}if (tstatValue == HIGH && tstatState == HIGH) //do nothing if input is still HIGH
{
}if (tstatValue == LOW && tstatState == HIGH) // if input swings LOW reset tstatState1 to LOW
{
tstatState1 = LOW;
}//if (tstatValue2 == HIGH)
//{
//digitalWrite(zone2,HIGH); // relay1 is power-on
//digitalWrite(zonereverse2,LOW); // relay1 is power-on
//}
//else
//{
//digitalWrite(zone2,LOW); //relay1 is power-off
//digitalWrite(zonereverse2,HIGH); // relay1 is power-on
//}//if (tstatValue3 == HIGH)
//{
//digitalWrite(zone3,HIGH); // relay1 is power-on
//digitalWrite(zonereverse3,LOW); // relay1 is power-on
//}//else
//{
//digitalWrite(zone3,LOW); //relay1 is power-off
//digitalWrite(zonereverse3,HIGH); // relay1 is power-on
//}//if (tstatValue4 == HIGH)
//{
//digitalWrite(zone4,HIGH); // relay1 is power-on
//digitalWrite(zonereverse4,LOW); // relay1 is power-on
//}//else
//{
//digitalWrite(zone4,LOW); //relay1 is power-off
//digitalWrite(zonereverse4,HIGH); // relay1 is power-on
//}
}
Now I do not know the best way to do this and I figure you peeps are more than able to guide me. I need help mind hurts too much coffee. Not enough water.
Thanks,
Dominic