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
#include "EspMQTTClient.h" | |
#define PIN_RED 23 // GIOP23 | |
#define PIN_GREEN 22 // GIOP22 | |
#define PIN_BLUE 21 // GIOP21 | |
EspMQTTClient client( | |
"MY_WIFI_SSID", | |
"MY_WIFI_PASSWORD", | |
"MY_BROKER_IP / HOSTNAME", | |
"MQTT_USERNAME", | |
"MQTT_PASSWORD", | |
"MQTT_CLIENT_ID"); | |
void setup() { | |
pinMode(PIN_RED, OUTPUT); | |
pinMode(PIN_GREEN, OUTPUT); | |
pinMode(PIN_BLUE, OUTPUT); | |
} | |
void loop() { | |
client.loop(); | |
} | |
void onConnectionEstablished() { | |
client.subscribe("zigbee2mqtt/Box Button", [](const String& payload) { | |
blink(); | |
}); | |
} | |
void blink() { | |
int x = 0; | |
do { | |
setColor(0, 201, 204); | |
delay(1000); | |
setColor(247, 120, 138); | |
delay(1000); | |
setColor(52, 168, 83); | |
delay(1000); | |
x++; | |
} while (x < 3); | |
} | |
void setColor(int R, int G, int B) { | |
analogWrite(PIN_RED, R); | |
analogWrite(PIN_GREEN, G); | |
analogWrite(PIN_BLUE, B); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment