RGB LED strip code questions (Sparkfun Pro Micro, LPD8806)

Hello everyone,

I've finally gotten the following code (mostly) working with my sparkfun pro micro, a 5m (160 pixel) led strip and a 5-position switch (yes, for a hula-hoop). Now I am wanting to add more cases (ie patterns) to the handlestrip() function. However, for the life of me, I cannot figure out how a few things work:

1) Does "tick" just continue to count up to 4,294,967,295 (because it is an unsigned long) and then stop? What is the point of this?

2) In handlestrip(case 3) below, does every pixel in the strip turn on when "tick" is a multiple of 100, and then off when "tick"/50 has a remainder of 1 (e.g. at 51; 101; 151; 201...)? Is there a better way to adjust the rate of "strobing?"

3) How would I implement the ledbeltkit functions found later in the code (colorwipe, colorchase, dither, larson scanner, etc.) into additional cases in handlestrip() while retaining the ability to cycle through colors?

4) Would it be possible to read the last color that was displayed on the strip/pixel and then display the opposite color? Or, would it be possible to do a strobe in predefined colors while still retaining the ability to cycle through colors? For example, when using one of the strobe functions, instead of turning one color on and off, I want it to strobe between two colors - one that comes from GetColor() and another that is predefined depending on what GetColor() returns. (So, anytime GetColor() returns red, the second strobe color will be yellow. Anytime GetColor() returns blue, the second strobe will be white.. etc.)

Thank you all in advance :D

code: http://pastebin.com/25t5T3ww

teaker: 1) Does "tick" just continue to count up to 4,294,967,295 (because it is an unsigned long) and then stop? What is the point of this?

It doesn't stop, it goes back to zero. There's no 'point', it's just how binary numbers work.

teaker: 2) In handlestrip(case 3) below, does every pixel in the strip turn on when "tick" is a multiple of 100, and then off when "tick"/50 has a remainder of 1 (e.g. at 51; 101; 151; 201...)? Is there a better way to adjust the rate of "strobing?"

Yes. Yes.

teaker: 3) How would I implement the ledbeltkit functions found later in the code (colorwipe, colorchase, dither, larson scanner, etc.) into additional cases in handlestrip() while retaining the ability to cycle through colors?

4) Would it be possible to read the last color that was displayed on the strip/pixel and then display the opposite color? Or, would it be possible to do a strobe in predefined colors while still retaining the ability to cycle through colors? For example, when using one of the strobe functions, instead of turning one color on and off, I want it to strobe between two colors - one that comes from GetColor() and another that is predefined depending on what GetColor() returns. (So, anytime GetColor() returns red, the second strobe color will be yellow. Anytime GetColor() returns blue, the second strobe will be white.. etc.)

It's all software so anything's possible... :)

Im about to start on an LED hula project myself.

I tackled #3 on a few projects and what I did was add an digitalread within any loop of those functions. If the button it hit, it will skip to the end.

Here is an example of the colorwipe:

void colorWipe(uint32_t c, uint8_t wait) {
  int i;
 
  for (i=0; i < strip.numPixels(); i++) {
//////////////////////  
  	 if(digitalRead(buttonPin) == HIGH){
	   while (digitalRead(buttonPin) == HIGH){ } //do nothing while its pressed (or count for hold)
	    mode++;
		goto buttonPress;}
///////////////////////////////////////
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
  //////////////////
  buttonPress:
  if (mode == nummodes) mode = 0;  // If its the last Mode, restart to 0 (Case1)
  return;
  //////////////////
}

Once the button it pressed, the mode++ will change the case number.
The GOTO will skip to the end of the effect,and the end of the case. Then it will move to the next case.
Once the mode++ hits all of the cases, it restarts at 0.

And this is the basic code for the loop and shows the cases

void loop() {
   if (digitalRead(buttonPin)==HIGH) mode++;   // UPDATE MODE if button is caught here
   if (mode == nummodes) mode = 0;  // If its the last Mode, restart to 0 (Case1)
	  while (digitalRead(button)==HIGH){
      //don't do anything else until the button is released
      }
     for (int i=0; i < strip.numPixels(); i++) { // Clear strip data before start of next effect
     strip.setPixelColor(i, 0);
     }
	}
  modeSelect();  //Defaults to 0 = Case 1
}
 
void modeSelect(){
  switch (mode){
    case 1:
        // Send a simple pixel chase in...
		colorChase(strip.Color(193,180,83), 20);   // blue
      break;
    case 2:
		// Fill the entire strip with...
		colorWipe(strip.Color(193,180,83), 20);     // gold
      break;
    case 3:
		// Color sparkles
		dither(strip.Color(0,0,127), 30);         // blue, slow
      break;
    case 4:
		scanner(193,180,83, 15);        // gold, slow
      break;
    case 5:
      wave(strip.Color(0,0,127), 4, 40);        // icy
      break;
  }
}

I would just make all of your current effects subfuctions, and just call the function in the cases.

May take some tweaking of this to work with what you have, but i have had good success with this method on a few projects.