mode and colour selection

Ok im sorry for my original attempt at this because i posted the wrong sketch to begin with which kind of shot me in the foot from the start. what i am trying to do is to upgrade a TRON legacy deluxe disc to add the ability to change colours by pushing a second button and leaving the existing button to transition through the ignition, blade spin and extinguish animations. my "perfect" scenario is that it will change colour without interrupting the blade spin/theater chase animation, but i am fine with it turning all the LED in the neopixel strip off before resuming the theater chase in the new color. the code i am using for the blade ring is:

#include <Adafruit_DotStar.h> //Comment out if using NeoPixels 



// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin.  When you
// press the button it will change to a new pixel animation.  Note that you need to press the
// button once to start the first animation!

//#include <Adafruit_NeoPixel.h> //commnt out if using DotStar

#ifdef __AVR__
#include <avr/power.h>
#endif


#define BUTTON_PIN   5    // Digital IO pin connected to the button.  This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily.  On a high -> low
// transition the button press logic will execute.

#define PIXEL_PIN    0    // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 60
#define NUMPIXELS 60
// set both of the above to the number of pixels in your strip
// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// Here's how to control the LEDs from any two pins:
#define DATAPIN    4
#define CLOCKPIN   3
Adafruit_DotStar strip = Adafruit_DotStar(
                           NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG);

bool oldState = HIGH;
int showType = 0;

void setup() {
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
int mode = 0;  // Start in the "Off" mode
void loop() {

  // check for a button press
  if (digitalRead(5) == LOW)  // button pressed
  {
    mode++;  // advance to the next mode
    if (mode == 3)
    {
      mode = 0; // go back to Off
    }
  }
}

  switch (mode) // execute code for one of the 3 modes:

  {
      {
      case 0: colorWipe(strip.Color(0, 0, 0), 10);
        break; // mode == OFF
        // add code for the "Off" mode here
        break;
      }
      {
      case 1: colorWipe(strip.Color(0, 0, 255), 5);
        // add code for the "Ignition" mode here
        break;
      }
      {
      case 2: theaterChase(0xff, 0, 0, 50); // mode == Spinning
        // add code for the "Spinning" mode here
        break;
      }
  }
}



  // Fill the dots one after the other with a color
  void colorWipe(uint32_t c, uint8_t wait) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
    }
    void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
      for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
        for (int q = 0; q < 3; q++) {
          for (int i = 0; i < NUM_LEDS; i = i + 3) {
            setPixel(i + q, red, green, blue);  //turn every third pixel on
          }
          showStrip();

          delay(SpeedDelay);

          for (int i = 0; i < NUM_LEDS; i = i + 3) {
            setPixel(i + q, 0, 0, 0);    //turn every third pixel off

          }

iam using a seconf pro trinket for the "C" ring and i have the proper sketch for that because all i need is a set of color wipe cases and i have that sketch working fine and can merely wire the color select switch into the second board and be ready to go. i have put together at least the start of a new sketch that looks like i have at least gotten to the point of it has both tactile switches in and ready to go, but i really dont know what the next step is. i have no real code experience and up to this point i have been able to identify existing code that i need for my projects and copy and paste it where it needs to go. any help i can get on how o write the code i need is greatly appreciated, but this is the new sketch i am building for the blade ring:

//#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
#include <Adafruit_NeoPixel.h> //commnt out if using DotStar

#ifdef __AVR__
#include <avr/power.h>
#endif

//This sketch is to let the TRON legacy disc cycle through a selection of colours each time the colour select button is pressed
//while simultaneously allowing it to cycle through the "ignition" "blade spin" and "extinguish" animations
//when the mode select button is pressed

#define PIXEL_PIN    0    // Digital IO pin connected to the NeoPixels.

int      head  = 0, tail = -10; // Index of first 'on' and 'off' pixels
uint32_t color = 0xFF0000;      // 'On' color (starts red)

//this sets he number of pixels in the strip
#define PIXEL_COUNT 45
#define NUMPIXELS 45


//chooses which strip is being used, comment out the one you are not using
//Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG)Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);



void setup()  {

#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pinMode(7, INPUT_PULLUP);  // Set pin 7 to be in input mode
  pinMode(8, INPUT_PULLUP);  // Set pin 8 to be in input mode
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  startAnimation();     //we use () because we are not passing any parameters
}
int mode = 0;  // Start in the "Off" mode

void loop() {
  // put your main code here, to run repeatedly:

}


void startAnimation() {
  for (int x = 0; x < NUMPIXELS * 3; x++) {
    strip.setPixelColor(head, color); // 'On' pixel at head
    strip.setPixelColor(tail, 0);     // 'Off' pixel at tail
    strip.show();                     // Refresh strip
    delay(20);                        // Pause 20 milliseconds (~50 FPS)

    if (++head >= NUMPIXELS) {        // Increment head index.  Off end of strip?
      head = 0;                       //  Yes, reset head index to start
      if ((color >>= 8) == 0)         //  Next color (R->G->B) ... past blue now?
        color = 0xFF0000;             //   Yes, reset to red
    }
    if (++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index
  }
}

How often are you reading the state of the switch? Not very.

How does colorWipe() or theaterChase() know that the switch was pressed? They don't.

If you want either of those functions to do something different before reaching the end of the cycle. you have to read the switch state in the functions or completely rewrite the code using NO for loops and NO delay()s. It CAN be done.

i realized i had posted the wrong sketch to begin with so i asked the admins to delete the previous thread so i could show what i was actually working with instead of a rough draft attempt. the code i posted in THIS thread is the code that works for my disc as it is now. what im trying to figure out specifically is how i can make the animations look for the colour that is currently selected by the color change button rather than having to actually code it into each animation as in making (strip.Color(0, 0, 255), 5); something like (strip.Color(the colour currently selected), 5); but i have not been able to find anything about having colour selection as an independent variable that the animation looks for rather than having the RGB values coded in directly if it is possible to do that. in terms of animation transitions, the existing sketch works perfectly and gives me accurate animations, the problem is that if i want to change colours, i have to plug it in, open the sketch and change the colour values when i want to be able to do that onboard instead. i have found various tutorials on how to multitask but none of them actually explain it in a way that someone with no coding experience can understand and what makes it worse is non of the tutorials i have found even address anything close to what i am trying to do.

i know how the color variable work with values from 0 to 255 for each colour, but is there a way to have each of the animations look for the colour in the color change function instead of being coded into the animation code itself?

then HOW do i add the ability to change colour without having to cycle through 4 different animation cycles to get to the right colour?

Turns out Adafruit wrote a tutorial about this very subject:

However, IMO, they went a little far with it in that they rewrote all the display patterns to be part of a class that inherits from the Adafruit_NeoPixel class. So, it may be kind of rough for those with limited coding experience. But, you may be able to glean the basic concepts of "deconstructing" the loops and making the code non-blocking.

im used to BASIC so the non linear flexibility of C is actually a bit of a stumbling block for me and is the main reason its a bit difficult for me to write the code. i can read what it is doing, i am having a hard time wrapping my head around doing everything as self contained tasks because i dont see how they tie together by being able to look at early lines to see how they are affecting later ones

In that case, you might need to put this project aside until you acquire the requisite coding skills to do it correctly. You need to build your knowledge by taking the time to learn the language and by tackling progressively more advanced programs.

The project you're attempting now simply won't come about by "cut and paste" programming. There's no way for someone to tell you how to do it, you just don't have the foundation to understand the advice.

thats the thing though, i dont know what any of it is doing, so far the only reason i have been able to get as far as i have is because someone wrote the original working code which is what i used to learn how to read what its doing and gained a basic understanding of the code. now i have people telling me "well this is the general structure..." but i havent been able to find out how to actually DO any of what i want to do because every time i find a sketch that looks like it performs a function that im looking for, i dont see anything i would expect to see such as the colors it cycles through being defined. i found a theater wipe sketch that has (color1, color2,) but nowhere in the sketch does it show HOW color1 and color2 were defined. i find something that looks like it might be a way to have it switch colors but it turns out that it makes several different pixels have different colours at the same time during the animation. i can find sketches for anything and everything under the sun except for the one thing im trying to do and the one time i find someone mention they did what im trying to do, they dont share a single line of code so i have something to work from to learn to write what i need to get what i want done. im not even asking people to write my code for me, im hoping someone can write a sample sketch with an example of how to make the colours change during a theater wipe and how to define which the colours so that i can take that and modify it for the rest of my animations or SOMETHING so that ihave an actual working example so i can actually grasp how this works, i dont learn well by just being told, i have to be able to see what it is that i am doing so i can figure it out. i catch on to things very quickly, but right now, im basically at the start of a maze but the door into the maze is seamless looking so i cant even identify which of the four walls of the room even HAS the door much less how to find the door to even start the maze. please help me understand what im trying to do here.

i ctually got lucky and a friend wrote my code for me. after seing the code in action (after a bit of debugging) i was able to actually grasp the concepts. my obstacle is im a high function autistic and the tutorials cover the general concepts but dont get into enough specific applications of them or how to apply them to a wide enough range of applications for me to see. the tutorials say "this command cycles through the color aray" but not HOW it does it for example. or another tutorial explains how to use a second buton to momentarily change the animation and let it go back to the original, but now how to cycle through the changes and leave them running. another thing they dont cover is how to fix problems such as the color cycle was having issues actually doing the colors i wanted and ONLY the colours i wanted, but it turns out the fix was simply telling the program to divide the number of colours in the array by itself to get the limit/reset cycle variable because the standard command of "if (color_array > color array then = 0" (sorry for the improper syntax but you get the point) was actually being affected by something else in the code which meant it had to be "if (color array)/(color array) is >color array then = 0" to correct it which was never covered in the tuyorials so by following the tutorials i would have been even further from getting this solved. after seeing the code for what i needed and comparing it to the tutorial examples though i understand it a lot more and will be able to use what i know to copy and paste the required blocks of code from what i have (simply to save time in typing, not to cheap out) and modify variables as needed for the new project. in any event here is the disc sketch so you can see how this differs from the examples in the tutorials and why the tutorials would not have been helpful to me:

//This is to allow a NeoPixel or DotStar strip to be cycled through a preset list of animations
//as well as to all the user to change the colours of the enimations while the animations are playing
//the start animation will send a pulse of blue, red and green down the strip to indicate the device is
//booted up and ready to go as well as allow a check for dead pixels or individualk colour elements
//TRON Legacy Identity disc Mk2 (replace with the name of the project being built)

//#include <Adafruit_DotStar.h> //Comment out if using NeoPixels
#include <Adafruit_NeoPixel.h> //commnt out if using DotStar


#ifdef _AVR_
#include <avr/power.h>
#endif


#define ANIMATION_BUTTON_PIN   5    // Digital IO pin connected to the button.  This will cycle through the animations.
#define COLOR_BUTTON_PIN   6    // Digital IO pin connected to the button.  This cycle through the colors.
#define PIXEL_PIN    4    // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 37
#define NUMPIXELS 37
// set both of the above to the number of pixels in your strip
// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
// Here's how to control the LEDs from any two pins:
#define DATAPIN    4
//#define CLOCKPIN   3 //comment out if using neopixel as clockpin is not required
//Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG); //comment out if using neopixels
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); //comment out if using dotstar

int      head  = 0, tail = -10; // Index of first 'on' and 'off' pixels
uint32_t color = 0xFF0000;      // 'On' color (starts red)



void setup() {
#if defined (_AVR_ATtiny85_)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  pinMode(ANIMATION_BUTTON_PIN, INPUT_PULLUP);
  pinMode(COLOR_BUTTON_PIN, INPUT_PULLUP);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  startAnimation();     //we use () because we are not passing any parameters
}
int mode = 0;  // Start in the "Off" mode

int colorindex = 0; //Starts in Red
int areLEDsBlank = 0;  //We did this so that the "Off" Mode isn't constantly writing to the LED Strip

//Adjust the colors here
uint32_t COLOR_ARRAY[] = {strip.Color(127, 0, 0), strip.Color(0, 255, 0), strip.Color(0, 0, 255)};


void loop() {

  // check for a button press
  if (digitalRead(ANIMATION_BUTTON_PIN) == LOW)  // button pressed
  {
    mode++;  // advance to the next mode
    if (mode == 4)
    {
      mode = 0; // go back to Off
    }
  }

  // check for a button press
  if (digitalRead(COLOR_BUTTON_PIN) == LOW)  // button pressed
  {
    colorindex++;  // advance to the next mode
    if (colorindex == sizeof(COLOR_ARRAY)/sizeof(COLOR_ARRAY[0]))
    {
      colorindex = 0; // go back to Red
    }
  }

  switch (mode) // execute code for one of the 3 modes:
  {
    case 0:
      if (areLEDsBlank != 0)
      {
        colorWipe(strip.Color(0, 0, 0), 10);
        areLEDsBlank = 0;
      }
      break; // mode == OFF

    case 1:          // add code for the "Ignition" mode here
      areLEDsBlank = 1;
      colorWipe(COLOR_ARRAY[colorindex], 5);
      break;

    case 2:          // add code for the "Spinning" mode here
      areLEDsBlank = 1;
      theaterChase(COLOR_ARRAY[colorindex], 25);
      break;
      
    case 3:          // add code for the "Ignition" mode here
      areLEDsBlank = 1;
      colorWipe(COLOR_ARRAY[colorindex], 10);
      break;
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q < 3; q++) {
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}


void startAnimation() {

for (int i = 0; i< 4*NUMPIXELS; i++)
{ 
  strip.setPixelColor(head, color); // 'On' pixel at head
  strip.setPixelColor(tail, 0);     // 'Off' pixel at tail
  strip.show();                     // Refresh strip
  delay(20);                        // Pause 20 milliseconds (~50 FPS)

  if (++head >= NUMPIXELS) {        // Increment head index.  Off end of strip?
    head = 0;                       //  Yes, reset head index to start
    if ((color >>= 8) == 0)         //  Next color (R->G->B) ... past blue now?
      color = 0x000000;             //   Yes, reset to red
  }
  if (++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index
}
}