-
-
Save dyadica/45cce156e8d1a1eade1e736d57e72524 to your computer and use it in GitHub Desktop.
This file contains 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
int led1 = D3; | |
void setup() | |
{ | |
// Set both LED pins as outputs | |
pinMode(led1, OUTPUT); | |
// Set both LED's to off by writing | |
// LOW to the pin. | |
digitalWrite(led1, LOW); | |
// Register the subscription and assign | |
// a handler for it | |
Particle.subscribe("ledToggle", myHandler); | |
} | |
// The handler for the subscription | |
void myHandler(String event, String data) | |
{ | |
if(data == "on") | |
digitalWrite(led1, HIGH); | |
if(data == "off") | |
digitalWrite(led1, LOW); | |
} |
This file contains 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
// Send an event by name | |
Particle.publish(const char *eventName); | |
Particle.publish(String eventName); | |
// Send data via a named event | |
Particle.publish(const char *eventName, const char *data); | |
Particle.publish(String eventName, String data); | |
// Return values | |
boolean (true or false) | |
// Example usage | |
bool success; | |
success = Particle.publish("button-pressed"); | |
if (!success) { | |
// triggered if event publish failed | |
} |
This file contains 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
void setup() | |
{ | |
Particle.subscribe("button-pressed", handler); | |
Serial.begin(9600); | |
} | |
void handler(String event, String data) | |
{ | |
Serial.print(event); | |
Serial.print(", data: "); | |
if (data) | |
{ | |
Serial.print(data); | |
else | |
Serial.print("NULL"); | |
} | |
Serial.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment