Skip to content

Instantly share code, notes, and snippets.

@jeremyricketts
Created January 2, 2015 05:00
Show Gist options
  • Save jeremyricketts/2ab6276fac18a6b13831 to your computer and use it in GitHub Desktop.
Save jeremyricketts/2ab6276fac18a6b13831 to your computer and use it in GitHub Desktop.
Spark Core Garage Door Controller
// Define the pins we're going to call pinMode on
int button = D6;
int Dee7 = D7; //Stock LED
int Dee4 = D4; //
// This routine runs only once upon reset
void setup() {
//Register our Spark function here
Spark.function("gdoor", gdoor);
pinMode(button, INPUT_PULLDOWN);
pinMode(Dee7, OUTPUT);
pinMode(Dee4, OUTPUT);
digitalWrite(Dee7, LOW); //Default state
digitalWrite(Dee4, LOW); //Default state
}
// This routine gets called repeatedly, like once every 5-15 milliseconds.
// Spark firmware interleaves background CPU activity associated with WiFi + Cloud activity with your code.
// Make sure none of your code delays or blocks for too long (like more than 5 seconds), or weird things can happen.
void loop() {
if (digitalRead(button) == HIGH) { // Button is not pushed
gdoor(""); // Do the thang.
delay(1000); // Wait a second if the person holds the button down.
};
}
int gdoor(String command) { // This actually triggers the door.
int state = 0;
digitalWrite(Dee4, HIGH); // Activate it.
delay(500); // Wait a tick.
digitalWrite(Dee4, LOW); // Set it back to the default state.
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment