Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorgreenleaf/969da39d71970e5db998f51584746fe7 to your computer and use it in GitHub Desktop.
Save trevorgreenleaf/969da39d71970e5db998f51584746fe7 to your computer and use it in GitHub Desktop.
int led1 = D0;
// the little blue LED on your board
int led2 = D7;
// when the device starts up it will run the setup function or when the device is reset
// void meaning it is not going to return a value
void setup() {
// We are going to tell our device that D0 and D7 (which we named led1 and led2 respectively) are going to be output
// (That means that we will be sending voltage to them, rather than monitoring voltage that comes from them)
// It's important you do this here, inside the setup() function rather than outside it or in the loop function.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
// register the cloud function
Particle.function("light", lightIt);
}
// this function automagically gets called upon a matching POST request
int lightIt(String command) {
if(command == "on"){
digitalWrite(led1, HIGH);
// some example functions you might have
// activateWaterHeater();
// activateWaterPump();
}
if(command == "off"){
digitalWrite(led1, LOW);
}
}
void loop() {
// To blink the LED, first we'll turn it on...
// digitalWrite(led1, HIGH);
// digitalWrite(led2, HIGH);
// // We'll leave it on for 1 second...
// delay(6000);
// // Then we'll turn it off...
// digitalWrite(led1, LOW);
// digitalWrite(led2, LOW);
// // Wait 1 second...
// delay(1000);
// And repeat!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment