void setup() {
Particle.subscribe("toggle_led", eventHandler);//, MY_DEVICES);
pinMode(D7, OUTPUT); // LED pin
Serial.begin(9600); // Optional: Debugging
}
void eventHandler(const char *event, const char *data) {
Serial.printlnf("Received event: %s, data: %s", event, data);
if (strcmp(data, "on") == 0) {
digitalWrite(D7, HIGH); // Turn on the LED
delay(1000); // Keep the LED on for 5 seconds
digitalWrite(D7, LOW); // Turn off the LED
}
}
void loop() {
// Continuously listen for events
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .