Servo or something turning off neopixels

Hello, i was wondering if anyone could take a look at this sketch and tell me why the functions front and rear turn the pixels off for a second or two then turn back on when the servo functions move. they usually complete their colour change but sometimes turn off before that. is it a case of too many millis timers, the servos blocking the front rear code, or something completly different. in a seperate sketch the servos work normal and the front rear functions work perfect in their own sketches.

`#define ESP32_RTOS  // Uncomment this line if you want to use the code with freertos only on the ESP32
                    // Has to be done before including "OTA.h"
#include "OTA.h"
#include "credentials.h"
#include "NoiascaLedControl.h"
#include <pwmWrite.h>
#include <FastLED.h>


const int servoPin1 = 18; //pie holo
const int servoPin2 = 19; //front holo 
const int servoPin3 = 21;  // rear holo

 Pwm pwm = Pwm();          //pwm for esp32

#define NUM_LEDS_PER_STRIP 7
CRGB leds1[NUM_LEDS_PER_STRIP];   //pie neo
CRGB leds2[NUM_LEDS_PER_STRIP];   //front neo
CRGB leds3[NUM_LEDS_PER_STRIP];   // rear neo

///////////////holo timers//////////////
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long interval1 = 3000;
unsigned long interval2 = 1000;
unsigned long interval3 = 1000;

/*
matrix logic pins
 */
const uint8_t LEDCS_PIN = 26;           // 26 LED CS or LOAD software spi
const uint8_t LEDCLK_PIN = 25;         // 25 LED Clock software spi
const uint8_t LEDDATA_PIN = 27;        // 27 LED DATA IN software spi
const uint8_t LED_MODULES = 5;     

LedControl lc = LedControl  (LEDDATA_PIN, LEDCLK_PIN, LEDCS_PIN, LED_MODULES);  // Software Bitbang - use this if you can't use Hardware SPI

/* we always wait a bit between updates of the display */
const unsigned long delaytime=100;

const int numCols = 8; // number of columns in LED matrix
const int numRows = 8; // number of rows in LED matrix
bool matrix[numCols][numRows]; // keep track of which LEDs are on or off

//////////////////psi////////////////

// Constants for LED strips
#define DATA_PIN_22   22   //front psi
#define DATA_PIN_23   23 //rear   psi
#define NUM_LEDSpsi      21
#define LED_TYPE      WS2812B
#define COLOR_ORDER   GRB
#define DATA_RATE     800000

// psi objects
CRGB leds4[NUM_LEDSpsi];
CRGB leds5[NUM_LEDSpsi];
// Timing variables
unsigned long previousMillisf = 0;
unsigned long previousMillisr = 0;
unsigned long interval4 = 0;
unsigned long interval5 = 0;
bool isRed = true;
bool isGreen = true;


void setup() {
  Serial.begin(115200);
  Serial.println("Booting");

  setupOTA("R2 HEAD test board", mySSID, myPASSWORD);////CHANGE FOR BOARD

  // Your setup code
   /* The MAX72XX needs to initialize hardware */
  lc.begin();
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
   lc.shutdown(1,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
   lc.setIntensity(1,8);
  /* and clear the display */
  lc.clearDisplay(0);
  lc.clearDisplay(1);
  
 FastLED.addLeds<NEOPIXEL, 4>(leds1, NUM_LEDS_PER_STRIP);        // pie neo pin
  FastLED.addLeds<NEOPIXEL, 17>(leds2, NUM_LEDS_PER_STRIP);      // front neo pin
  FastLED.addLeds<NEOPIXEL, 16>(leds3, NUM_LEDS_PER_STRIP);      // rear neo pin
////////// holo servo initilisation/////////
 pwm.attach(servoPin1, 0, 1000, 2000);
  pwm.attach(servoPin2, 1, 1000, 2000);
  pwm.attach(servoPin3, 2, 1000, 2000); 
  // pwm.attach(servoPin1, 0, 1000, 2000, 0, 1, true);   ////inverse pwm
  //pwm.attach(servoPin2, 1, 1000, 2000, 0, 1, true);       ////inverse pwm
  //pwm.attach(servoPin3, 2, 1000, 2000, 0, 1, true);      ////inverse pwm
 
   pwm.writeServo(servoPin1, 90); // Stop
   pwm.writeServo(servoPin2, 90); // Stop
   pwm.writeServo(servoPin3, 90); // Stop
 //////////////////psi setup//////////////////
  FastLED.addLeds<LED_TYPE, DATA_PIN_22, COLOR_ORDER>(leds4, NUM_LEDSpsi).setCorrection(TypicalLEDStrip);
  FastLED.addLeds<LED_TYPE, DATA_PIN_23, COLOR_ORDER>(leds5, NUM_LEDSpsi).setCorrection(TypicalLEDStrip);
theaterChaseRainbow();
  setRandomInterval();

  //////////////////// matrix lines on startup////////////////
   for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,true); // turns on LED at col, row
      lc.setLed(1,col,row,true); // turns on LED at col, row
      delay(50);
    }
  }

  for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,false); // turns off LED at col, row
       lc.setLed(1,col,row,false); // turns off LED at col, row
      delay(50);
      //lc.clearDisplay(0);// clear screen
      //lc.clearDisplay(1);// clear screen
    }
  }
}


void rando() {
  // Turn on or off random LEDs
  int count = 0;
  while (count < 20) {
    int x = random(numCols);
    int y = random(numRows);

    if (matrix[x][y] == false) {
      lc.setLed(0, x, y, true);
       lc.setLed(1, x, y, true);
      matrix[x][y] = true;
      count++;
    }
    else {
      lc.setLed(0, x, y, false);
       lc.setLed(1, x, y, false);
      matrix[x][y] = false;
    }
  }
  
  delay(50); // wait a short time before updating the LEDs
}



void loop() {
#ifdef defined(ESP32_RTOS) && defined(ESP32)
#else // If you do not use FreeRTOS, you have to regulary call the handle method.
  ArduinoOTA.handle();
#endif

  // Your code here
 front();
 rear();
 
 rando();
 ArduinoOTA.handle();
  //servo1();
  ArduinoOTA.handle();
 // servo2();
  ArduinoOTA.handle();
  //servo3();
  ArduinoOTA.handle();
  
}

void servo1(){
  static byte state1 = 0;
  unsigned long currentMillis = millis();

  switch(state1) {
    case 0:
      fill_solid (leds1, 7, CRGB(179, 230, 255));
      FastLED.show();
      previousMillis1 = currentMillis;
      state1++;
      break;
    case 1:
      if (currentMillis - previousMillis1 >= interval1) {
        pwm.writeServo(servoPin1, (random (140 ,180)));
                previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis1 >= interval2) {
        pwm.writeServo(servoPin1, 90); // Stop
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis1 >= interval3) {
        pwm.writeServo(servoPin1,(random (0 , 50)));
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis1 >= interval2) {
        pwm.writeServo(servoPin1, 90); // Stop
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis1 >= interval3) {
        FastLED.clear(true);
        previousMillis1 = currentMillis;
        state1 = 0;
        interval1 = random(2000, 5000);
        interval2 = random(100, 500);
        interval3 = random(3000, 5000);
      }
      break;
  }
}

void servo2(){
  static byte state2 = 0;
  unsigned long currentMillis = millis();

  switch(state2) {
    case 0:
      fill_solid (leds2, 7, CRGB(179, 230, 255));
      FastLED.show();
      previousMillis2 = currentMillis;
      state2++;
      break;
    case 1:
      if (currentMillis - previousMillis2 >= interval1) {
         pwm.writeServo(servoPin2, (random (140 ,180)));
       
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis2 >= interval2) {
        pwm.writeServo(servoPin2, 90); // Stop
        
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis2 >= interval3) {
         pwm.writeServo(servoPin2,(random (0 , 50)));
       
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis2 >= interval2) {
        pwm.writeServo(servoPin2, 90); // Stop
        
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis2 >= interval3) {
        FastLED.clear(true);
        previousMillis2 = currentMillis;
        state2 = 0;
        interval1 = random(2000, 5000);   //led time
        interval2 = random(500, 1000);    // moving time then stop
        interval3 = random(1000, 5000);   // wait between moves
      }
      break;
  }
}



void servo3(){
  static byte state3 = 0;
  unsigned long currentMillis = millis();

  switch(state3) {
    case 0:
      fill_solid (leds3, 7, CRGB(179, 230, 255));
      FastLED.show();
      previousMillis3 = currentMillis;
      state3++;
      break;
    case 1:
      if (currentMillis - previousMillis3 >= interval1) {
         pwm.writeServo(servoPin3, (random (140 ,180)));
        
        previousMillis3 = currentMillis;
        state3++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis3 >= interval2) {
        pwm.writeServo(servoPin3, 90); // Stop
       
        previousMillis1 = currentMillis;
        state3++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis1 >= interval3) {
         pwm.writeServo(servoPin3,(random (0 , 50)));
       
        previousMillis1 = currentMillis;
        state3++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis3 >= interval2) {
        pwm.writeServo(servoPin3, 90); // Stop
        
        previousMillis3 = currentMillis;
        state3++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis3 >= interval3) {
        FastLED.clear(true);
        previousMillis3 = currentMillis;
        state3 = 0;
        interval1 = random(1000, 5000);
        interval2 = random(100, 500);
        interval3 = random(1000, 5000);
      }
      break;
  }
}
// Set all LEDs of a strip to a specified color
void setLEDsColor(CRGB* leds, int numLeds, const CRGB& color) {
  for (int i = 0; i < numLeds; i++) {
    leds[i] = color;
  }
}

// Set a random interval between 1 and 5 seconds
void setRandomInterval() {
  interval4 = random(5000, 10000);
  interval5 = random(5000, 10000);
}


void theaterChaseRainbow() {
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  for (int a = 0; a < 30; a++) {  // Repeat 30 times...
    for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
   //   setLEDsColor(leds5, NUM_LEDSpsi, 0, 0, 0); // Set all LEDs to off
//      setLEDsColor(leds4, NUM_LEDSpsi, 0, 0, 0); // Set all LEDs to off
      
      // 'c' counts up from 'b' to end of strip in increments of 3...
      for (int c = b; c < NUM_LEDSpsi; c += 3) {
        // hue of LED 'c' is offset by an amount to make one full
        // revolution of the color wheel (range 65536) along the length
        // of the strip (NUM_LEDSpsi steps):
        int hue = firstPixelHue + c * 65536L / NUM_LEDSpsi;
        leds4[c] = CHSV(hue, 255, 255); // hue -> RGB
        leds5[c] = CHSV(hue, 255, 255); // hue -> RGB
      }
      
      FastLED.show(); // Update both LED strips
      
      delay(50); // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}


void front(){
 unsigned long currentMillisf = millis();

  // Control the first set of LEDs on pin 22
  if (currentMillisf - previousMillisf >= interval4) {
    if (isRed) {
      setLEDsColor(leds4, NUM_LEDSpsi, CRGB::Red);
      isRed = false;
    } else {
      setLEDsColor(leds4, NUM_LEDSpsi, CRGB::Blue);
      isRed = true;
    }

    FastLED.show(); // Update the first LED strip

    setRandomInterval(); // Set a new random interval

    previousMillisf = currentMillisf; // Update the previous millis
  }
}

void rear(){
  
  unsigned long currentMillisr = millis();
  
   // Control the second set of LEDs on pin 23
  if (currentMillisr - previousMillisr >= interval5) {
    if (isGreen) {
      setLEDsColor(leds5, NUM_LEDSpsi, CRGB::Green);
      isGreen = false;
    } else {
      setLEDsColor(leds5, NUM_LEDSpsi, CRGB::Yellow);
      isGreen = true;
    }

    FastLED.show(); // Update the second LED strip

    setRandomInterval(); // Set a new random interval

    previousMillisr = currentMillisr; // Update the previous millis
  }
}

this is all being compiled on a esp32 wroom dev board

What is the board?

Esp32 dev. It compiles as wroom on the arduino

My guess would be that using the servo functions disturb the precise timing required by the LEDs

I was wondering if there was any way around it. Ive just learned the esp32 has 2 cores, so maybe ill have more luck playing with that and putting one sketch on 1 core and another on the other core.

Could be pin or timer conflicts.

Looking in fastspi_esp32.h, it has #define FASTLED_ESP32_SPI_BUS VSPI which uses pins 18 and 19 that conflict with your servo pins.

Not sure what timers are in use by libraries other than ESP32-ESP32S2-AnalogWrite. Your servos are currently using timer 0 and timer 1. See PWM Channel Configuration here.

Since you can choose any channel and timer to use, I would try attaching the servos to a higher channel that uses higher timer numbers, i.e:

pwm.attachServo(servoPin1, 12, 1000, 2000);  // uses timer 2
pwm.attachServo(servoPin2, 13, 1000, 2000);  // uses timer 2
pwm.attachServo(servoPin3, 14, 1000, 2000);  // uses timer 3

Make sure you've updated to the latest version of ESP32-ESP32S2-AnalogWrite which is 5.0.2

With this latest version, you can use the library as above or in a similar way as the Arduiuino Servo Library.

#include "Servo.h"

Servo myservo = Servo();

myservo.attach(servoPin1, 12, 1000, 2000);  // uses timer 2
myservo.attach(servoPin2, 13, 1000, 2000);  // uses timer 2
myservo.attach(servoPin3, 14, 1000, 2000);  // uses timer 3

Maybe ill try moving them around to see if that helps but the servos work by themselves, so ill move the new neopixels first

Well another stupid question answered. So for those playing at home, in my sketch i had neos attached to servos when they moved. Then after they stopped the led turned off,(see where im going with this) so instead of using fastled clear i should have just showed the individual leds to black. Clear was turning off all the neopixels on the board.



#define ESP32_RTOS  // Uncomment this line if you want to use the code with freertos only on the ESP32
                    // Has to be done before including "OTA.h"
#include "OTA.h"
#include "credentials.h"
#include "NoiascaLedControl.h"
#include <pwmWrite.h>
#include <FastLED.h>

////blynk/////
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "ssid";
char pass[] = "password";

//////////////////////////////////////////////////pin 35 used for input rx and 32 for tx at a later date//////////////



const int servoPin1 = 18; //pie holo
const int servoPin2 = 19; //front holo 
const int servoPin3 = 21;  // rear holo

 Pwm pwm = Pwm();          //pwm for esp32

#define NUM_LEDS_PER_STRIP 7
CRGB leds1[NUM_LEDS_PER_STRIP];   //pie neo
CRGB leds2[NUM_LEDS_PER_STRIP];   //front neo
CRGB leds3[NUM_LEDS_PER_STRIP];   // rear neo

///////////////holo timers//////////////
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long interval1 = 3000;
unsigned long interval2 = 1000;
unsigned long interval3 = 1000;
unsigned long holodelay = 15000; //(random (1000 , 5000));
unsigned long PreviousMillis = 0;
///////////////psi/////////////////////////////////////
// Constants for LED strips
#define DATA_PIN_22   22   //front psi
#define DATA_PIN_23   23 //rear   psi
#define NUM_LEDSpsi      21
#define LED_TYPE      WS2812B
#define COLOR_ORDER   GRB
#define DATA_RATE     800000

// LED strip objects
CRGB leds4[NUM_LEDSpsi];
CRGB leds5[NUM_LEDSpsi];
///psi timing//////
unsigned long previousMillisf = 0;
unsigned long previousMillisr = 0;
unsigned long interval4 = 0;
unsigned long interval5 = 0;
bool isRed = true;
bool isGreen = true;


/*
matrix logic pins
 */
const uint8_t LEDCS_PIN = 26;           // 26 LED CS or LOAD software spi
const uint8_t LEDCLK_PIN = 25;         // 25 LED Clock software spi
const uint8_t LEDDATA_PIN = 27;        // 27 LED DATA IN software spi
const uint8_t LED_MODULES = 5;     

LedControl lc = LedControl  (LEDDATA_PIN, LEDCLK_PIN, LEDCS_PIN, LED_MODULES);  // Software Bitbang - use this if you can't use Hardware SPI

/* we always wait a bit between updates of the display */
const unsigned long delaytime=100;

const int numCols = 8; // number of columns in LED matrix
const int numRows = 8; // number of rows in LED matrix
bool matrix[numCols][numRows]; // keep track of which LEDs are on or off


//////blynk vpins///
BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V7);  // will cause BLYNK_WRITE(V1) to be executed
}

BLYNK_WRITE(V7) // Executes when the value of virtual pin 1 changes
{
  if(param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
     theaterChaseRainbow();
  }
  }
//////////////////////////

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
//////blynk////

 Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  setupOTA("R2 HEAD  still test", mySSID, myPASSWORD);////CHANGE FOR BOARD

  // Your setup code
   /* The MAX72XX needs to initialize hardware */
  lc.begin();
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
   lc.shutdown(1,false);
   lc.shutdown(2,false);
   lc.shutdown(3,false);
   lc.shutdown(4,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
   lc.setIntensity(1,8);
    lc.setIntensity(2,8);
     lc.setIntensity(3,8);
      lc.setIntensity(4,8);
  /* and clear the display */
  lc.clearDisplay(0);
  lc.clearDisplay(1);
  lc.clearDisplay(2);
  lc.clearDisplay(3);
  lc.clearDisplay(4);
  
 FastLED.addLeds<NEOPIXEL, 4>(leds1, NUM_LEDS_PER_STRIP);        // pie neo pin
  FastLED.addLeds<NEOPIXEL, 17>(leds2, NUM_LEDS_PER_STRIP);      // front neo pin
  FastLED.addLeds<NEOPIXEL, 16>(leds3, NUM_LEDS_PER_STRIP);      // rear neo pin
////////// holo servo initilisation/////////
 pwm.attach(servoPin1, 0, 1000, 2000);
  pwm.attach(servoPin2, 1, 1000, 2000);
  pwm.attach(servoPin3, 2, 1000, 2000); 
 
   pwm.writeServo(servoPin1, 90); // Stop
   pwm.writeServo(servoPin2, 90); // Stop
   pwm.writeServo(servoPin3, 90); // Stop
 ////////////psi////////////////////////////////////
  FastLED.addLeds<LED_TYPE, DATA_PIN_22, COLOR_ORDER>(leds4, NUM_LEDSpsi).setCorrection(TypicalLEDStrip);
  FastLED.addLeds<LED_TYPE, DATA_PIN_23, COLOR_ORDER>(leds5, NUM_LEDSpsi).setCorrection(TypicalLEDStrip);
theaterChaseRainbow();
  setRandomInterval();


  //////////////////// matrix lines on startup////////////////
   for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,true); // turns on LED at col, row
      lc.setLed(1,col,row,true); // turns on LED at col, row
       lc.setLed(2,col,row,true); // turns on LED at col, row
        lc.setLed(3,col,row,true); // turns on LED at col, row
         lc.setLed(4,col,row,true); // turns on LED at col, row
      delay(50);
    }
  }

  for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,false); // turns off LED at col, row
       lc.setLed(1,col,row,false); // turns off LED at col, row
        lc.setLed(2,col,row,false); // turns off LED at col, row
         lc.setLed(3,col,row,false); // turns off LED at col, row
          lc.setLed(4,col,row,false); // turns off LED at col, row
      delay(50);
      //lc.clearDisplay(0);// clear screen
      //lc.clearDisplay(1);// clear screen
    }
  }  
 
}


void rando() {
  // Turn on or off random LEDs
  int count = 0;
  while (count < 20) {
    int x = random(numCols);
    int y = random(numRows);

    if (matrix[x][y] == false) {
      lc.setLed(0, x, y, true);
       lc.setLed(1, x, y, true);
       lc.setLed(2, x, y, true);
       lc.setLed(3, x, y, true);
       lc.setLed(4, x, y, true);
      matrix[x][y] = true;
      count++;
    }
    else {
      lc.setLed(0, x, y, false);
       lc.setLed(1, x, y, false);
        lc.setLed(2, x, y, false);
         lc.setLed(3, x, y, false);
          lc.setLed(4, x, y, false);
      matrix[x][y] = false;
    }
  }
  
  delay(40); // wait a short time before updating the LEDs
}





void loop() {
#ifdef defined(ESP32_RTOS) && defined(ESP32)
#else // If you do not use FreeRTOS, you have to regulary call the handle method.
  ArduinoOTA.handle();
#endif
 Blynk.run();


 front();
  rear();
 
  // Your code here
 unsigned long currentMillis = millis();
 rando();

 
  
 if (currentMillis - PreviousMillis >= holodelay) {
  servo1();
  PreviousMillis = currentMillis;
  holodelay = 10000; //(random (8000 , 15000));
  PreviousMillis = 0;
  
 
// ArduinoOTA.handle();
 if (currentMillis - PreviousMillis >= holodelay) {
  servo2();
  PreviousMillis = currentMillis;
  holodelay = 10000; //(random (8000 , 15000));
  PreviousMillis = 0;
  
  
  
  //ArduinoOTA.handle();
  if (currentMillis - PreviousMillis >= holodelay) {
  servo3();
  PreviousMillis = currentMillis;
  holodelay = 10000; //(random (8000 , 15000));
  PreviousMillis = 0;
  
 } 
 }
 } 
}

void servo1(){
  static byte state1 = 0;
  unsigned long currentMillis = millis();

  switch(state1) {
    case 0:
    holo1on();
    
      previousMillis1 = currentMillis;
      state1++;
      break;
    case 1:
      if (currentMillis - previousMillis1 >= interval1) {
        pwm.writeServo(servoPin1, (random (140 ,180)));
                previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis1 >= interval2) {
        pwm.writeServo(servoPin1, 90); // Stop
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis1 >= interval3) {
        pwm.writeServo(servoPin1,(random (0 , 50)));
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis1 >= interval2) {
        pwm.writeServo(servoPin1, 90); // Stop
        previousMillis1 = currentMillis;
        state1++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis1 >= interval3) {
        //FastLED.clear(true);
        holo1off();
        
        previousMillis1 = currentMillis;
        state1 = 0;
     
      }
      break;
  }
}

void servo2(){
  static byte state2 = 0;
  unsigned long currentMillis = millis();

  switch(state2) {
    case 0:
     // fill_solid (leds2, 7, CRGB(179, 230, 255));
      //FastLED.show();
      holo2on();
      
      previousMillis2 = currentMillis;
      state2++;
      break;
    case 1:
      if (currentMillis - previousMillis2 >= interval1) {
         pwm.writeServo(servoPin2, (random (140 ,180)));
       
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis2 >= interval2) {
        pwm.writeServo(servoPin2, 90); // Stop
        
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis2 >= interval3) {
         pwm.writeServo(servoPin2,(random (0 , 50)));
       
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis2 >= interval2) {
        pwm.writeServo(servoPin2, 90); // Stop
        
        previousMillis2 = currentMillis;
        state2++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis2 >= interval3) {
        //FastLED.clear(true);
        holo2off();
        
        previousMillis2 = currentMillis;
        state2 = 0;
      
      }
      break;
  }
}



void servo3(){
  static byte state3 = 0;
  unsigned long currentMillis = millis();

  switch(state3) {
    case 0:
    holo3on();
     // fill_solid (leds3, 7, CRGB(179, 230, 255));
     //FastLED.show();
      previousMillis3 = currentMillis;
      state3++;
      break;
    case 1:
      if (currentMillis - previousMillis3 >= interval1) {
         pwm.writeServo(servoPin3, (random (140 ,180)));
        
        previousMillis3 = currentMillis;
        state3++;
      }
      break;
    case 2:
      if (currentMillis - previousMillis3 >= interval2) {
        pwm.writeServo(servoPin3, 90); // Stop
       
        previousMillis1 = currentMillis;
        state3++;
      }
      break;
    case 3:
      if (currentMillis - previousMillis1 >= interval3) {
         pwm.writeServo(servoPin3,(random (0 , 50)));
       
        previousMillis1 = currentMillis;
        state3++;
      }
      break;
    case 4:
      if (currentMillis - previousMillis3 >= interval2) {
        pwm.writeServo(servoPin3, 90); // Stop
        
        previousMillis3 = currentMillis;
        state3++;
      }
      break;
    case 5:
      if (currentMillis - previousMillis3 >= interval3) {
       // FastLED.clear(true);
        holo3off();
        
        previousMillis3 = currentMillis;
        state3 = 0;
       
      }
      break;
  }
}

void holo1on(){
fill_solid (leds1, 7, CRGB(179, 230, 255));
      FastLED.show();
  
}

void holo1off(){
 //FastLED.clear(true);
   fill_solid (leds1, 7, CRGB::Black);
   
      FastLED.show();
}

void holo2off(){
 //FastLED.clear(true);
  
    fill_solid (leds2, 7, CRGB::Black);
     
      FastLED.show();
}

void holo3off(){
 //FastLED.clear(true);
   
     fill_solid (leds3, 7, CRGB::Black);
      FastLED.show();
}

void holo2on(){
    fill_solid (leds2, 7, CRGB(179, 230, 255));
      FastLED.show();
}

void holo3on(){
    fill_solid (leds3, 7, CRGB(179, 230, 255));
      FastLED.show();
}

// Set all LEDs of a strip to a specified color
void setLEDsColor(CRGB* leds, int numLeds, const CRGB& color) {
  for (int i = 0; i < numLeds; i++) {
    leds[i] = color;
  }
}

// Set a random interval between 1 and 5 seconds
void setRandomInterval() {
  interval4 = random(5000, 15000);
  interval5 = random(5000, 15000);
}


void theaterChaseRainbow() {
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  for (int a = 0; a < 30; a++) {  // Repeat 30 times...
    for (int b = 0; b < 3; b++) { // 'b' counts from 0 to 2...
   //   setLEDsColor(leds5, NUM_LEDSpsi, 0, 0, 0); // Set all LEDs to off
//      setLEDsColor(leds4, NUM_LEDSpsi, 0, 0, 0); // Set all LEDs to off
      
      // 'c' counts up from 'b' to end of strip in increments of 3...
      for (int c = b; c < NUM_LEDSpsi; c += 3) {
        // hue of LED 'c' is offset by an amount to make one full
        // revolution of the color wheel (range 65536) along the length
        // of the strip (NUM_LEDSpsi steps):
        int hue = firstPixelHue + c * 65536L / NUM_LEDSpsi;
        leds4[c] = CHSV(hue, 255, 255); // hue -> RGB
        leds5[c] = CHSV(hue, 255, 255); // hue -> RGB
      }
      
      FastLED.show(); // Update both LED strips
      
      delay(50); // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}

void front(){
 unsigned long currentMillisf = millis();

  // Control the first set of LEDs on pin 22
  if (currentMillisf - previousMillisf >= interval4) {
    if (isRed) {
      setLEDsColor(leds4, NUM_LEDSpsi, CRGB::Red);
      isRed = false;
    } else {
      setLEDsColor(leds4, NUM_LEDSpsi, CRGB::Blue);
      isRed = true;
    }

    FastLED.show(); // Update the first LED strip

    setRandomInterval(); // Set a new random interval

    previousMillisf = currentMillisf; // Update the previous millis
  }
}

void rear(){
  
  unsigned long currentMillisr = millis();
  
   // Control the second set of LEDs on pin 23
  if (currentMillisr - previousMillisr >= interval5) {
    if (isGreen) {
      setLEDsColor(leds5, NUM_LEDSpsi, CRGB::Green);
      isGreen = false;
    } else {
      setLEDsColor(leds5, NUM_LEDSpsi, CRGB::Yellow);
      isGreen = true;
    }

    FastLED.show(); // Update the second LED strip

    setRandomInterval(); // Set a new random interval

    previousMillisr = currentMillisr; // Update the previous millis
  }
}

so no i have a different issue. The servos dont seem to wait the required time before moves and the leds wont turn off. I took the servo code and put it into wokwi and it wouldn’t seem to move past the state 0.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.