Code for photon Garage Door

//PUT YOUR VARIABLES HERE

int relay1 = D0;
int relay2 = D3;
int reed1 = D1;
int reed2 = D4;
bool disabled = false;

int relay1Pulse(String command){
digitalWrite(relay1,LOW);
delay(1000);
digitalWrite(relay1,HIGH);
return 1;
}

int relay2Pulse(String command){
digitalWrite(relay2,LOW);
delay(1000);
digitalWrite(relay2,HIGH);
return 1;
}

int statusCheck(String command){
int status1 = digitalRead(reed1);
int status2 = digitalRead(reed2);
if(status1 == LOW && status2 == HIGH){
return 1;
}
else if(status1 == HIGH && status2 == LOW){
return 2;
}
else if(status1 == LOW && status2 == LOW){
return 3;
}
else if(status1 == HIGH && status2 == HIGH){
return 0;
}
else{
return -1;
}
}

bool isDST(int day, int month, int dow)
{
int currMonth = Time.month();
int currDay = Time.day();
int currDayOfWeek = Time.weekday();

//January, february, and december are out.
if (currMonth < 3 || currMonth > 11) {
return false;
}
//April to October are in
if (currMonth > 3 && currMonth < 11) {
return true;
}

int previousSunday = currDay – currDayOfWeek;
//In march, we are DST if our previous sunday was on or after the 8th.
if (currMonth == 3) {
return previousSunday >= 8;
}

//In november we must be before the first sunday to be dst.
//That means the previous sunday must be before the 1st.
return previousSunday <= 0;
}

int getTime(String command) {
int currTime = Time.hour()-6;
if (currTime < 0) {
currTime =+ 24;
}
if (isDST) {
currTime++;
}
return currTime;
}

int setDisabled(String command) {
disabled = true;
return 0;
}
int setEnabled(String command) {
disabled = false;
return 0;
}
int getState(String command) {
if(disabled==true) {
return 0;
}
else {
return 1;
}
}

void setup()
{
Serial.begin(9600);

Spark.function(“getState”, getState);
Spark.function(“setEnabled”, setEnabled);
Spark.function(“setDisabled”, setDisabled);

Spark.function(“relayOne”, relay1Pulse);
Spark.function(“relayTwo”, relay2Pulse);
Spark.function(“status”, statusCheck);
Spark.function(“getTime”, getTime);

pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(reed1, INPUT_PULLDOWN);
pinMode(reed2, INPUT_PULLDOWN);

digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
//PUT YOUR SETUP CODE HERE
delay(30000);
if(statusCheck(“check”) == 1) {
relay1Pulse(“pulse”);
}
else if(statusCheck(“check”) == 2) {
relay2Pulse(“pulse”);
}
else if(statusCheck(“check”) == 3) {
relay1Pulse(“pulse”);
relay2Pulse(“pulse”);
}
}
void loop()
{
//PUT YOUR LOOP CODE HERE
delay(60000);
if((getTime(“time”) < 4) && (statusCheck(“check”) > 0) && (disabled==false)) {
if(statusCheck(“check”) == 1) {
relay1Pulse(“pulse”);
}
else if(statusCheck(“check”) == 2) {
relay2Pulse(“pulse”);
}
else if(statusCheck(“check”) == 3) {
relay1Pulse(“pulse”);
relay2Pulse(“pulse”);
}
}

}