#include #include "colorutils.h" #include "colorpalettes.h" #if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) #warning "Requires FastLED 3.1 or later; check github for latest code." #endif //This is where we adjust things to match our unique project: #define NUM_STRIPS 3 #define NUM_LEDS_PER_STRIP 24 #define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS #define BRIGHTNESS 255 // 255 is full brightness, 128 is half #define SATURATION 255 // 0-255, 0 is pure white, 255 is fully saturated color #define BUTTON_PIN 2 // Connect the button to GND and one of the pins. #define UPDATES_PER_SECOND 100 #define NUM_MODES 10 //Update this number to the highest number of "cases" uint8_t gHue = 0; // rotating "base color" used by many of the patterns uint16_t STEPS = 30;// STEPS set dynamically once we've started up uint16_t SPEED = 30;// SPEED set dynamically once we've started up CRGB leds[NUM_LEDS]; CRGBPalette16 currentPalette; TBlendType currentBlending; int ledMode = 0; uint8_t colorLoop = 1; const TProgmemPalette16 MyColors_p PROGMEM = { CRGB:: DarkBlue, CRGB:: HotPink, CRGB:: Teal, CRGB:: BlueViolet, CRGB:: DodgerBlue, CRGB:: DeepPink, CRGB:: Turquoise, CRGB:: Indigo, CRGB:: DarkBlue, CRGB:: HotPink, CRGB:: Teal, CRGB:: BlueViolet, CRGB:: DodgerBlue, CRGB:: DeepPink, CRGB:: Turquoise, CRGB:: Indigo, }; byte prevKeyState = HIGH; // button is active low //sort the sequence of ARGB LEDs according Radiant-D mounting position //reorder LEDs sequence int db[] = {2,3,1,4,0,5,8,6,7, 13,14,12,15,11,16,10,17,9, 25,24,26,23,18,22,19,21,20}; //------------------SETUP------------------ void setup() { delay( 2000 ); // power-up safety delay // Assign pin 3, 5 and 6 as LED singal pin FastLED.addLeds(leds, 0, NUM_LEDS_PER_STRIP); FastLED.addLeds(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP); FastLED.addLeds(leds, NUM_LEDS_PER_STRIP*2, NUM_LEDS_PER_STRIP); FastLED.setBrightness( BRIGHTNESS ); currentBlending = LINEARBLEND; //all of these will be blended unless I tell them not to be pinMode(BUTTON_PIN, INPUT_PULLUP); } //------------------MAIN LOOP------------------ void loop() { byte currKeyState = digitalRead(BUTTON_PIN); if ((prevKeyState == LOW) && (currKeyState == HIGH)) { shortKeyPress(); } prevKeyState = currKeyState; static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ switch (ledMode) { //FastLED has a bunch of built-in "palettes" to choose from: //RainbowColors_p is all the colors of the rainbow //PartyColors_p is all the colors of the rainbow minus greens //RainbowStripeColors_p is all the colors of the rainbow divided into stripes //HeatColors_p is reds and yellows, white, and black //LavaColors_p is more reds and orangey colors //ForestColors_p is greens and yellows //OceanColors_p is lots of blues and aqua colors //CloudColors_p is blues and white //MyColors_p is whatever you define above //The group of colors in a palette are sent through a strip of LEDS in speed and step increments youve chosen //You can change the SPEED and STEPS to make things look exactly how you want //SPEED refers to how fast the colors move. Higher numbers = faster motion //STEPS refers to how wide the bands of color are. Based on the palette & number of LEDs, some look better at different steps case 0: {currentPalette = RainbowColors_p; SPEED = 100; STEPS = 8;} break; case 1: {currentPalette = RainbowStripeColors_p; SPEED = 50; STEPS = 8; currentBlending = NOBLEND;} break; case 2: {currentPalette = PartyColors_p; SPEED = 150; STEPS = 48; currentBlending = LINEARBLEND;} break; case 3: {currentPalette = MyColors_p; SPEED = 75; STEPS = 48;} break; case 4: {currentPalette = HeatColors_p; SPEED = 100; STEPS = 11;} break; case 5: {SetupWatermelonPalette(); SPEED = 125; STEPS = 8;} break; case 6: {currentPalette = ForestColors_p; SPEED = 200; STEPS = 48;} //all steps look good. Speed should be high. break; case 7: {currentPalette = OceanColors_p; SPEED = 100; STEPS = 8;} // break; case 8: {SetupNewPalette(); SPEED = 250; STEPS = 16; currentBlending = NOBLEND;} break; case 9: {currentPalette = LavaColors_p; SPEED = 100; STEPS = 8;} break; case 10: {currentPalette = CloudColors_p; SPEED = 100; STEPS = 8;} break; } FillLEDsFromPaletteColors( startIndex); FastLED.show(); FastLED.delay(1000 / SPEED); } void shortKeyPress() { ledMode++; if (ledMode > NUM_MODES) { ledMode=0; } } void FillLEDsFromPaletteColors( uint8_t colorIndex) { for( int i = 0; i < NUM_LEDS; i++) { leds[db[i]] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending); colorIndex += STEPS; } } void SetupNewPalette() { fill_solid( currentPalette, 16, CRGB::Black); // set half of the LEDs to the color selected here // Play with the color, steps, and speed to get different results. currentPalette[0] = CRGB::DodgerBlue; currentPalette[1] = CRGB::DodgerBlue; currentPalette[2] = CRGB::DodgerBlue; currentPalette[3] = CRGB::DodgerBlue; currentPalette[8] = CRGB::DodgerBlue; currentPalette[9] = CRGB::DodgerBlue; currentPalette[10] = CRGB::DodgerBlue; currentPalette[11] = CRGB::DodgerBlue; } // This function sets up a palette of purple and green stripes. // Play with the color, steps, and speed to get different results. void SetupWatermelonPalette() { CRGB Pink = CHSV(HUE_PINK, 255, 255); CRGB Green = CHSV( HUE_GREEN, 255, 255); CRGB black = CRGB::Black; currentPalette = CRGBPalette16( Green, Green, Green, Green, Pink, Pink, Pink, Pink, Green, Green, Green, Green, Pink, Pink, Pink, Pink ); }