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.