Heres my final code for my LED shorts. with my local sports team colors (blue and gold). The secret mode is green for when we lost (the other teams colors)
I kept the other default effect (chase and wave) in there but I did not use them in my selection.
This code works great with the button.
#include "LPD8806.h"
#include "SPI.h"
/*****************************************************************************/
// Full 5m LPD8806 STRIP
/*****************************************************************************/
#define holdTime 3000 //used to time button hold for special function
#define buttonPin 23 //Default button pin
//To DISABLE Auto USB to save power
const int usb_usb_disable = 0; //disabled usb is enable to save power
int mode = 0; // default mode is off (0)
int nummodes = 8; //number of total modes
long btnDnTime; // time the button was pressed down
long btnUpTime; // time the button was released
// Number of RGB LEDs in strand:
int nLEDs = 160;
//LPD8806 strip = LPD8806(32, dataPin, clockPin); // In case use different pins.
LPD8806 strip = LPD8806(nLEDs); // Default to SPI pins 21 and 22 on Teensy 2.00
void setup() {
if (usb_usb_disable) Serial.end(); //Disable USB is the usb_usb_disable is 0
Serial.begin(9600); // Set up serial communication at 9600bps to debug via usb
pinMode(buttonPin, INPUT); //Enable BUTTON
// Start up the LED strip
strip.begin(); // Start up the LED strip
// Update the strip, to start they are all 'off'
for (int i = 0; i < 160; i++){
strip.setPixelColor(i, 0, 0,0);
strip.show();
}
strip.show();
//Set OUTPUT to pins to save power
for (int i=0; i<20; i++){ pinMode(i, OUTPUT); }
for (int i=24; i<46; i++){ pinMode(i, OUTPUT); }
}
/************************************************************/
// function prototypes, do not remove these!
void colorChase(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void dither(uint32_t c, uint8_t wait);
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
void wave(uint32_t c, int cycles, uint8_t wait);
void rainbowCycle(uint8_t wait);
void police(int);
void failure(int);
void modeSelect();
void returnModeSelect();
uint32_t Wheel(uint16_t WheelPos);
/************************************************************/
/******************************************************************************/
// Main Loop Function //
/******************************************************************************/
void loop() {
//Serial.println(mode); // OFF
if (digitalRead(buttonPin)==LOW){
Serial.println("BUTTON OFF"); // OFF
} delay(50);
if (digitalRead(buttonPin)==HIGH){
Serial.println("BUTTON ON"); // ON
};
if (mode == 0) {
for (int i = 0; i < 160; i++){
strip.setPixelColor(i, 0, 0,0);
strip.show();
}
}
/*****************************************************************************/
if(digitalRead(buttonPin) == HIGH){ //Runs when button is pressed
Serial.println("Button pressed, going to returnModeSelect function");
returnModeSelect(); //Run function to change mode
Serial.println("Finished returnModeSelect function, going to modeSelect");
}
/*****************************************************************************/
modeSelect(); //Defaults to 0 = Case 1
if (mode > 7) mode = 0;
}
/******************************************************************************/
// Select Mode Function //
/******************************************************************************/
void modeSelect(){
switch (mode){
case 1:
Serial.println("ColorWipe & Dither");
// Fill the entire strip with...
colorWipe(strip.Color(0,0,127), 10); // blue
dither(strip.Color(105,70,0), 20); // yellow, slow
dither(strip.Color( 0, 0,127), 20); // blue, slow
dither(strip.Color(0,0,0), 5); // black, fast
dither(strip.Color(105,70,0), 20); // yellow, slow
dither(strip.Color(0,0,0), 5); // black, fast
dither(strip.Color( 0, 0,127), 20); // blue, slow
dither(strip.Color(105,70,0), 2); // yellow, slow
break;
case 2:
Serial.println("POLICE");
police(250, 10); // Delay and Repetitions
break;
case 3:
Serial.println("POLICE FAST");
police(100, 10); // Delay and Repetitions
break;
case 4:
Serial.println("Back-and-forth lights");
scanner(105,70,0, 20); // gold, slow
scanner( 0, 0,127, 15); // blue, fast
break;
case 5:
Serial.println("ALL");
colorWipe(strip.Color(0,0,127), 10); // blue
dither(strip.Color(105,70,0), 20); // yellow, slow
dither(strip.Color( 0, 0,127), 20); // blue, slow
dither(strip.Color(0,0,0), 5); // black, fast
dither(strip.Color(105,70,0), 20); // yellow, slow
dither(strip.Color(0,0,0), 5); // black, fast
dither(strip.Color( 0, 0,127), 20); // blue, slow
dither(strip.Color(105,70,0), 2); // yellow, slow
police(250, 15); // Delay and Repetitions
scanner(105,70,0, 20); // gold, slow
scanner( 0, 0,127, 15); // blue, fast
colorWipe(strip.Color(105,70,0), 10); // gold
dither(strip.Color( 0, 0,127), 15); // blue, slow
dither(strip.Color(105,70,0), 20); // yellow, slow
dither(strip.Color(0,0,0), 15); // black, fast
scanner(105,70,0, 15); // gold, slow
scanner( 0, 0,127, 10); // blue, fast
police(250,10);
break;
case 6:
Serial.println("rainbow");
rainbowCycle(0);
break;
case 7:
Serial.println("rainbow");
failure(250,15);
break;
}
}