Cycling through RGB color array with a momentary switch

AHHH ok so im starting to understand! From this ive gotten a momentary to switch to toggle the LEDs on. Now i would like it to do 2 things.

Set up a counter to count itself ++ everytime so that i can cycle through it like this

OFF>RED>BLUE>GREEN>OFF

More or less i need it to cycle through these modes (im guessing by using a counter) and then turn off.

#include "SPI.h"
#include "WS2801.h"



const int buttonPin = 4;     // the number of the pushbutton pin
int dataPin = 2;
int clockPin = 3;
int counter = 0;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply


// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
WS2801 strip = WS2801(25, dataPin, clockPin);

// Optional: leave off pin numbers to use hardware SPI
// (pinout is then specific to each board and can't be changed)
//WS2801 strip = WS2801(25);

void setup() {
  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);  
  
 
  strip.begin();

  // Update LED contents, to start they are all 'off'
  strip.show();
}


void loop() {
  // Some example procedures showing how to display to the pixels
  
   // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
   
   counter++;
     
     strip.setPixelColor(0, Color(0,0,255));
     strip.setPixelColor(1, Color(144,0,0));
     strip.show();   // write all the pixels out
  } 


  }

 void rainbow(uint8_t wait) {
  int i, j;

  for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 255));
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Slightly different, this one makes the rainbow wheel equally distributed 
// along the chain
void rainbowCycle(uint8_t wait) {
  int i, j;

  for (j=0; j < 256 * 5; j++) {     // 5 cycles of all 25 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 96-color wheel
      // (thats the i / strip.numPixels() part)
      // Then add in j which makes the colors go around per pixel
      // the % 96 is to make the wheel cycle around
      strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}




/* Helper functions */

// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
  if (WheelPos < 85) {
    return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if (WheelPos < 170) {
    WheelPos -= 85;
    return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170; 
    return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}
[code/]

Hi ToyAndgames and welcome.

Please edit your post and enclose your code in [ code ] tags (not quote tags - they're different!).

Also it looks like you lost some lines a the bottom of the code...

Paul

Done and thank you!!!! Ill get used to this place soon!

Bump :D

Ok then, next have a look at this example:

http://arduino.cc/en/Tutorial/ButtonStateChange