Created
September 21, 2015 18:42
-
-
Save harrisonhjones/c491db119eefba69a4ce to your computer and use it in GitHub Desktop.
Particle IO - InternetButton - IFTTT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "InternetButton/InternetButton.h" | |
#include "math.h" | |
// Set up lots of global variables that we'll be using | |
InternetButton b = InternetButton(); | |
uint8_t button1 = 0; | |
uint8_t button2 = 0; | |
uint8_t button3 = 0; | |
uint8_t button4 = 0; | |
uint8_t buttonAll = 0; | |
void setup() { | |
// Starting InternetButton b | |
b.begin(); | |
} | |
/* loop(), in contrast to setup(), runs all the time. Over and over again. | |
Remember this particularly if there are things you DON'T want to run a lot. Like Spark.publish() */ | |
void loop() { | |
if(b.allButtonsOn()){ | |
if(!buttonAll){ | |
buttonAll = 1; | |
Spark.publish("allbuttons",NULL, 60, PRIVATE); | |
b.rainbow(10); | |
} | |
} | |
else {buttonAll = 0;} | |
// OK, I'll explain this structure once... | |
if(b.buttonOn(1)){ // If button1 is on | |
if(!button1){ // and hasn't already been on | |
button1 = 1; // then you should know that it's on now | |
Spark.publish("button1",NULL, 60, PRIVATE); // and publish that it's on | |
b.ledOn(3, 0, 255, 0); // GREEN | |
} | |
} | |
else {button1 = 0;} // but if it's not on, we should reset this | |
// so we'll know when it comes on again | |
if(b.buttonOn(2)){ | |
if(!button2){ | |
button2 = 1; | |
Spark.publish("button2",NULL, 60, PRIVATE); | |
b.ledOn(6, 0, 0, 255); // BLUE | |
} | |
} | |
else {button2 = 0;} | |
if(b.buttonOn(3)){ | |
if(!button3){ | |
button3 = 1; | |
Spark.publish("button3",NULL, 60, PRIVATE); | |
b.ledOn(9, 255, 0, 255); // MAGENTA | |
} | |
} | |
else {button3 = 0;} | |
if(b.buttonOn(4)){ | |
if(!button4){ | |
button4 = 1; | |
Spark.publish("button4",NULL, 60, PRIVATE); | |
b.ledOn(9, 255, 0, 0); // RED | |
} | |
} | |
else {button4 = 0;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment