#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <WiFiClientSecure.h>
#include <LEDStripDriver.h>
const char* ssid = "ASUS";
const char* password = "97983740";
const char* mqtt_server = "broker.mqttdashboard.com";
const char* mqtt_user = "Zaia_Enterprise";
const char* mqtt_pswd = "87177972";
char messageBuffer[50];
WiFiClient espClient;
PubSubClient client(espClient);
// DIN=GPIO16, CIN=GPIO14 in this example
LEDStripDriver led = LEDStripDriver(16, 14);
unsigned long currentTime;
unsigned long startTime;
unsigned long period = 1000;
bool power = false;
int countR;
int countG;
int countB;
void setup_wifi()
{
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
Serial.println();
Serial.print("connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(2000);
}
void setup()
{
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop()
{
client.loop();
if (!client.connected())
{
reconnect();
}
if (power == true)
{
RainbowEffect();
}
}
void reconnect()
{
while (!client.connected())
{
Serial.println("Attempting MQTT connection...");
if (client.connect("Reception"))
{
Serial.println("Connected to MQTT server");
client.subscribe("RGB/Output");
}
else
{
Serial.print("Failed to connect to MQTT...");
Serial.println();
Serial.println("Attempting to connect again in 3 seconds.");
delay(3000);
}
}
}
void callback(char* topic, byte* payload, unsigned int length)
{
Serial.println();
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
Serial.print("length : ");
Serial.println(length);
memcpy(messageBuffer, payload, length);
messageBuffer[length] = '\0';
Serial.print("the payload is : ");
Serial.println(messageBuffer);
if (strcmp(messageBuffer, "on") == 0)
{
{
Serial.print("turning ");
Serial.println(messageBuffer);
digitalWrite(LED_BUILTIN, LOW);
power = true; //activate rainbow
}
}
else if (strcmp(messageBuffer, "off") == 0)
{
{
Serial.print("turning ");
Serial.println(messageBuffer);
digitalWrite(LED_BUILTIN, HIGH);
OffRainbow();
power = false; //stop the rainbow
}
}
}
void OffRainbow()
{
led.setColor(); // turn off
}
void RainbowEffect()
{
int ledcolor = random(6); //this randomly selects a number between 0 and 5
currentTime = millis();
if (currentTime - startTime >= period)
{
switch (ledcolor) {
case 0: //if ledcolor equals 0 transition to red
led.setColor(255,0,0);
break;
case 1: //if ledcolor equals 1 transition to green
led.setColor(0,255,0);
break;
case 2: //if ledcolor equals 2 transition to blue
led.setColor(0,0,255);
break;
case 3: //if ledcolor equals 3 transition to yellow
led.setColor(255,255,0);
break;
case 4: //if ledcolor equals 4 transition to cyan
led.setColor(0,255,255);
break;
case 5: //if ledcolor equals 5 transition magenta
led.setColor(250,160,250);
break;
}//rainbow here
startTime = currentTime;
}
}
I need help troubleshooting void RainbowEffect(). The strip does not light up when given command