Hi ronxtcdabass!
Apologies for the radio silence - it's been a crazy few days, and it always takes quite some time to read code and see what is going on 😁
I'm really not familiar with the IRCClient, so I do not know if the library maybe conflicts with other libraries.
First of all, you should probably consider cleaning up your code a little bit - just so it becomes more readable for others or when trying to debug something. Don't feel bad though, my code at times becomes a mess as well and then I just have to sit down and clean up.
Here an example of your loop() function after cleaning up ...
Use proper indentation and add spacing and such to make things more readable.
void loop() {
// Sound
analog_sample();
EVERY_N_MILLIS(1000/FRAMES_PER_SECOND) { // Optionally set the display frame rate to a fixed frame rate without
// resorting to the blocking method of FastLED.delay(1000/FRAMES_PER_SECOND).
gHue++;
FastLED.show();
}
// Try to connect to chat. If it loses connection try again
if (!client.connected()) {
Serial.println("Attempting to connect to " + ircChannel );
// Attempt to connect, Second param is not needed by Twitch
if (client.connect(TWITCH_BOT_NAME, "", TWITCH_OAUTH_TOKEN))
{
client.sendRaw("JOIN " + ircChannel);
Serial.println("connected and ready");
// Show if connected
fill_solid(leds, NUM_LEDS, CRGB::Green);
FastLED.delay(300);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.delay(300);
sendTwitchMessage("ready to 💡 start with !fx");
} else {
Serial.println("failed... try again in 5 seconds");
for (int i = 0; i < 5; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
// Wait 5 (10) seconds before retrying
delay(5000);
}
return;
}
client.loop();
}
You can also simplify the code a little bit by removing some parts that were originally added so my code could be used with FastLED and NeoPixel - but you're using FastLED so we can remove this.
// Apply LED color changes
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
Once removed, replace all occurances of "showStrip();" with "FastLED.show();"
Same goes for the "setPixel" function which can be removed by removing this part of the code
// ***************************************
// ** FastLed/NeoPixel Common Functions **
// ***************************************
// Set a LED color (not yet visible)
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
and replace every (where Pixel, Red, Green and Blue are parameters that can be different)
setPixel(Pixel, Red, Green, Blue);
with
leds[Pixel].setRGB( Red, Green, Blue);
The "SetAll()" function can be removed as well and each call to SetAll(Red,Green,Blue) can be replaced with a "fill_solid(leds, NUM_LEDS, CRGB(Red,Green,Blue));" function call (you've used them before);
// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
After that clean up; Now a few things to keep in mind:
1) An Arduino, or similar microcontroller, are not designed to do multitasking.
So changing the hue of your LEDs and checking Twitch IRC at the same time may conflict (timing wise). So there may be some trickery needed there. This is where I can see changing the Hue every second may be a challenge.
Tip: some (maybe even all?) ESP32 models have dual core processors, and do allow some of this to be done at the same time a little better. But it will take time and effort to learn and see how this works.
2) Libraries additionally can conflict, especially when timing becomes critical (which could be the case in your situation).
Especially for #2 I'd always test certain pieces of code in separate sketched - just to make sure they work. I assume you've already done this.
Having said all that, lets look at one problem at a time ... do I understand this right;
You're saying the "client.connected()" keeps failing and it therefor keeps trying to connect like a crazy person?
Or is this function called too often?