Assigning Specific Case Values

I have a sketch that is controlling some strip LED's. I have the arduino hooked up to a microphone sensor where I do a simple read, if it "hears" music I want it to run one of several patterns and when it doesn't hear music (digital read of 0) if turns off.

I'm running the different patterns using a switch case in the code below, it randomly selects between one of two patterns:

if (sensorVal == 1) { 
  
  
  byte randtest = random(0, 1); //randomly selects between specific colors
   switch (randtest)
   
   {
     case 0:
       twinkle();
       
         break;
      case 1:
       allflashcolor();
      
         break;
    }
   }

Rather than randomly assigning a value to the randtest to run the switch case, I'd like to assign it a specific set of values. For example, I'd like randtest to be the number 1, 6 times in a row, then the number 0, 8 times in a row, and so on as I add more cases and then start again at the beginning. In other words, right now as we go through the loop, randtest looks something like this:

randtest = 0,1,0,0,1,0,1,1,0,0,0

It's randomonly switching between one and zero, but I'd like to follow a certain pattern like this:

randtest = 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,

and then start at the beginning again and repeat this pattern.

Any help would be appreciated.

After 28 posts, you surely know how to Serial.print() values in your program to see what you are getting for numbers and don't need someone to guess for you.

Paul

There are multiple ways you could do this, but for the most flexibility in creating patterns, I would recommend using an array:

byte patterh[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

You can find more information on using arrays here:

I had actually tried what you suggested, but then I get an error that "switch quantity not an integer"

ericgrphone:
I had actually tried what you suggested, but then I get an error that "switch quantity not an integer"

Post the code that gave you that error