hey guys. I am a bit perplexed by my code as to why it is not working... any suggestions would be great. Below I have some code that listens for an incoming MQTT topic and then based on if it was the one that published the topic or it was another device it does stuff.
Currently my problem lies in when some other device publishes a topic. It finds it and parses the incoming char array to check to see if its from someone else. It then puts some neopixels in a while loop to light them all up white.
my problem is that not all the neopixels light up and I dont know why. currently I have 9 neopixels but only 7 light up. If I define it having 11 pixels all 9 light up but the last one is green. weird.
I have put a debug in the while loop for serial output to see if it actually is counting all the way to 9. It IS actually reaching all the way to 9 so I dont know why the setpixelcolor 1-9 is not doing ALL 9.
Any suggestions?
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println(" ");
Serial.print("Payload Array 0 = ");
Serial.println((char)payload[0]);
Serial.println(CLIENT_ID_INT);
if (payload[0] == CLIENT_ID_INT )
{Serial.println("I published the hash");
Serial.println(payload[0]);
int count = 0;
while (count <= 5)
{
count++;
Serial.println(count);
}
}
else
{
int i = 1;
while (i <= PIXEL_COUNT)
{
pixels.setPixelColor( i, 255,255,255);
Serial.println (i);
i++;
}
pixels.show();
Serial.println("Someone else published the hash");
}
Serial.println();
Serial.println("-----------------------");
}
if you need to view the full code - Family_Lights/Family_lights.ino at master · davidginn524/Family_Lights · GitHub