Last active
January 25, 2023 22:37
-
-
Save fwartner/f5a45f23c10cedc329622b751a40adb7 to your computer and use it in GitHub Desktop.
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 "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