Add switch to activate function

Hello, I would like the program

CylonBounce

 to start and loop on pressing the button on input 4.
When you press the same button again, it stops executing.
I have a big problem to do this, there is a lot of information on how to do it on LED.

I assume that you need to create a global variable, I just can't assign its value depending on whether the program is executing or not.
Thank you very much for your help and best regards.
#include "FastLED.h"
#define NUM_LEDS 9
CRGB leds[NUM_LEDS];
#define PIN 10

void setup()
{
  pinMode(8,INPUT_PULLUP);
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() 

{


  int pushButton = digitalRead(4);
  if(pushButton == LOW)
  {
    CylonBounce(0, 0, 0xff, 1, 160, 160);
  }else{
     leds[0] = CRGB::Black; FastLED.show(); delay(30);
  }

delay(100);
  
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
 
  delay(ReturnDelay);
  FastLED.clear ();
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

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
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

You set pin 8 to pinMode INPUT_PULLUP, but read pin 4. To which pin is the button connected?

With your code, once fixed, the Cylon animation will play as long as the button is held and stop when the button is released. If you want the animation to play with one press and turn off with the next press (toggle) you can use the state change detection method. [

See here for the state change with active low (wired to ground, low when pressed) button.](https://forum.arduino.cc/index.php?topic=711767.0)

Here is an example to show toggling the animation. There is a flag that enable and disables the playing of the animation. I used pin 4 for the switch (button).
You need to hold the button a second to turn the animation off because there are delay() calls in the animation code.

#include "FastLED.h"
#define NUM_LEDS 9
CRGB leds[NUM_LEDS];
#define PIN 10

const byte buttonPin = 4;

boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button
boolean enableCylon = HIGH;

void setup()
{
   pinMode(buttonPin, INPUT_PULLUP);
   FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop()

{
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            enableCylon = !enableCylon;
         }
      }
      lastButtonState = buttonState;
   }

   if (enableCylon == LOW)
   {
      CylonBounce(0, 0, 0xff, 1, 160, 160);
   }
   else
   {
      leds[0] = CRGB::Black; FastLED.show(); delay(30);
   }
   //delay(100);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{

   for (int i = 0; i < NUM_LEDS - EyeSize - 2; i++)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }

   delay(ReturnDelay);

   for (int i = NUM_LEDS - EyeSize - 2; i > 0; i--)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }

   delay(ReturnDelay);
   FastLED.clear ();
}

void showStrip()
{
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
#endif
}

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
}

void setAll(byte red, byte green, byte blue)
{
   for (int i = 0; i < NUM_LEDS; i++ )
   {
      setPixel(i, red, green, blue);
   }
   showStrip();
}
Thank you so much. You really helped me a lot.

You would be so nice and you would add a second
NewKITT
 and third

rainbowCycle

animations to this program that would loop in a loop after pressing the button once.

After a second press, it would turn off as it is now.
Thank you
void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

byte * Wheel(byte WheelPos) {
  static byte c[3];
 
  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;

  FastLED.clear ();
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

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
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}
void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
 FastLED.clear ();
}

void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
  FastLED.clear ();
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

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
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

Not sure what you want. Are those 2 new buttons?

Why don’t you try to write the code and I will help to get it right?

I am over 60 years old, I try to learn programming but mainly DIY. Thank you very much for your help.

With the same button I would like to choose from these three effects.
I wish they would change in a loop after one press, so with each single press one effect jumps.

 And his long press turns them off.

If that's not a lot of trouble then please do it for me. If not, I will try to do it myself and you will just help me and thank you so much anyway.

Look at the state change detection example. See that it has a counter that counts button presses. You can use that and an if, else if, else structure or a switch-case structure to choose which animation to play.

I am over 70 and started learning C++ about 5 years ago, so I know how it is. I can get you started and help along the way, but you won't learn much if I do it all for you.

See How to use button to start/stop the loop

Ok, i add the function

rainbowCycle
NewKITT
I tried to fight the counting. Unfortunately, I can't do that. Please help
#include "FastLED.h"
#define NUM_LEDS 9
CRGB leds[NUM_LEDS];
#define PIN 10

const byte buttonPin = 4;

boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button
boolean enableCylon = HIGH;
boolean enableNewKITT = HIGH;
boolean enablerainbowCycle = HIGH;
int counter = 1;
void setup()
{
   pinMode(buttonPin, INPUT_PULLUP);
   FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
   Serial.begin(9600);
}

void loop()

{
   static unsigned long timer = 0;
   unsigned long interval = 50;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            enableCylon = !enableCylon;
            counter++;
      
         }
      }
      lastButtonState = buttonState;
   }

   if (enableCylon == LOW && counter > 4 )
   {
      CylonBounce(0, 0, 0xff, 1, 80, 80);
   }
      if (enableCylon == LOW && counter > 6 )
   {
      CylonBounce(0, 0, 0xff, 1, 160, 160);
   }
   
   else
   {
      leds[0] = CRGB::Black; FastLED.show(); delay(30);
   }
   //delay(100);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{

   for (int i = 0; i < NUM_LEDS - EyeSize - 2; i++)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }

   delay(ReturnDelay);

   for (int i = NUM_LEDS - EyeSize - 2; i > 0; i--)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }

   delay(ReturnDelay);
   FastLED.clear ();
}
void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
  CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
 FastLED.clear ();
}

void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i =((NUM_LEDS-EyeSize)/2); i>=0; i--) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i<=((NUM_LEDS-EyeSize)/2); i++) {
    setAll(0,0,0);
   
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
   
    setPixel(NUM_LEDS-i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(NUM_LEDS-i-j, red, green, blue);
    }
    setPixel(NUM_LEDS-i-EyeSize-1, red/10, green/10, blue/10);
   
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
}

void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
  FastLED.clear ();
}


void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}

byte * Wheel(byte WheelPos) {
  static byte c[3];
 
  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }

  return c;

  FastLED.clear ();
}
void showStrip()
{
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
#endif
}

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
}

void setAll(byte red, byte green, byte blue)
{
   for (int i = 0; i < NUM_LEDS; i++ )
   {
      setPixel(i, red, green, blue);
   }
   showStrip();
}

This code cycles through the 3 animations, CylonBounce, NewKITT and rainbowCycle. The code starts with the strip off. Ideally first push chooses CylonBounce, second NewKITT and third rainbowCycle. The problem is that the animations are written with delays so the program is not very responsive. The button needs to be held down or clicked several times to get the animation to switch. The animations need to be rewritten with non blocking code (no delay(), no long for loops, no long while loops).

But this code shows how to choose the animation based on the buttonPushCounter using if, else if, else structure.

#include "FastLED.h"
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];
#define PIN 10

const byte buttonPin = 4;

boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button
int buttonPushCounter = 0;
int numberOfAnimations = 3;

void setup()
{
   pinMode(buttonPin, INPUT_PULLUP);
   FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop()

{
   static unsigned long timer = 0;
   unsigned long interval = 20;  // check switch 20 times per second
   if (millis() - timer >= interval)
   {
      timer = millis();
      // read the pushbutton input pin:
      buttonState = digitalRead(buttonPin);
      // compare the new buttonState to its previous state
      if (buttonState != lastButtonState)
      {
         if (buttonState == LOW)
         {
            buttonPushCounter ++;
            FastLED.clear ();
            showStrip();
         }
         if (buttonPushCounter > numberOfAnimations)
         {
            buttonPushCounter = 0;
         }
      }
      lastButtonState = buttonState;
   }

   if (buttonPushCounter == 0) // strip off
   {
      FastLED.clear ();
      showStrip();
   }
   else if (buttonPushCounter == 1)
   {
      CylonBounce(0, 0, 0xff, 1, 160, 160);
   }
   else if (buttonPushCounter == 2)
   {
      NewKITT(0xff, 0, 0xff, 2, 160, 160);
   }
   else if (buttonPushCounter == 3)
   {
      rainbowCycle(10);
   }
   else
   {
      buttonPushCounter = 0;
   }
   //delay(100);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{

   for (int i = 0; i < NUM_LEDS - EyeSize - 2; i++)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }
}

void rainbowCycle(int SpeedDelay)
{
   byte *c;
   uint16_t i, j;

   for (j = 0; j < 256 * 5; j++) // 5 cycles of all colors on wheel
   {
      for (i = 0; i < NUM_LEDS; i++)
      {
         c = Wheel(((i * 256 / NUM_LEDS) + j) & 255);
         setPixel(i, *c, *(c + 1), *(c + 2));
      }
      if (digitalRead(buttonPin) == LOW) // get out of for loop
      {
         j = 256*6;
      }
      showStrip();
      delay(SpeedDelay);
   }
}


void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{
   RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
   LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
   OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
   CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
   FastLED.clear ();
}

void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{
   for (int i = ((NUM_LEDS - EyeSize) / 2); i >= 0; i--)
   {
      setAll(0, 0, 0);

      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);

      setPixel(NUM_LEDS - i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(NUM_LEDS - i - j, red, green, blue);
      }
      setPixel(NUM_LEDS - i - EyeSize - 1, red / 10, green / 10, blue / 10);

      showStrip();
      delay(SpeedDelay);
   }
   delay(ReturnDelay);
}

void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{
   for (int i = 0; i <= ((NUM_LEDS - EyeSize) / 2); i++)
   {
      setAll(0, 0, 0);

      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);

      setPixel(NUM_LEDS - i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(NUM_LEDS - i - j, red, green, blue);
      }
      setPixel(NUM_LEDS - i - EyeSize - 1, red / 10, green / 10, blue / 10);

      showStrip();
      delay(SpeedDelay);
   }
   delay(ReturnDelay);
}

void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{
   for (int i = 0; i < NUM_LEDS - EyeSize - 2; i++)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }
   delay(ReturnDelay);
}

void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay)
{
   for (int i = NUM_LEDS - EyeSize - 2; i > 0; i--)
   {
      setAll(0, 0, 0);
      setPixel(i, red / 10, green / 10, blue / 10);
      for (int j = 1; j <= EyeSize; j++)
      {
         setPixel(i + j, red, green, blue);
      }
      setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
      showStrip();
      delay(SpeedDelay);
   }
   delay(ReturnDelay);
   FastLED.clear ();
}

void showStrip()
{
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
#endif
}

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
}

void setAll(byte red, byte green, byte blue)
{
   for (int i = 0; i < NUM_LEDS; i++ )
   {
      setPixel(i, red, green, blue);
   }
   showStrip();
}

byte * Wheel(byte WheelPos)
{
   static byte c[3];

   if (WheelPos < 85)
   {
      c[0] = WheelPos * 3;
      c[1] = 255 - WheelPos * 3;
      c[2] = 0;
   }
   else if (WheelPos < 170)
   {
      WheelPos -= 85;
      c[0] = 255 - WheelPos * 3;
      c[1] = 0;
      c[2] = WheelPos * 3;
   }
   else
   {
      WheelPos -= 170;
      c[0] = 0;
      c[1] = WheelPos * 3;
      c[2] = 255 - WheelPos * 3;
   }

   return c;

   FastLED.clear ();
}

Non-blocking coding tutorials:
Several things at a time.
Beginner’s guide to millis().
Blink without delay().

Thank you very much. Everything as I wanted