/* aanimations * * By: Can't recall where I found this. Maybe Stefan Petrick. * * Modified by: Andrew Tuline * * Date: January, 2017 * * This sketch demonstrates how to blend between two animations running at the same time. * */ #include "FastLED.h" // FastLED library. #include "string.h" #if FASTLED_VERSION < 3001000 #error "Requires FastLED 3.1 or later; check github for latest code." #endif #define NUM_STRIPS 3 #define NUM_LEDS_PER_STRIP 16 #define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS #define BUTTON_PIN 2 // Connect the button to GND and one of the pins. byte prevKeyState = HIGH; // button is active low // Global variables can be changed on the fly. uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. // have 3 independent CRGBs - 2 for the sources and one for the output CRGB leds[NUM_LEDS]; CRGB leds2[NUM_LEDS]; CRGB leds3[NUM_LEDS]; //int db[] = {0,1,2,3,4,5,6,7,8,13,12,11,10,9,17,16,15,14}; //sort the sequence of ARGB LEDs according Radiant-D mounting position int db[] = {5,6,4,7,3,8,2,9,1,10,0,11,15,12,14,13, 21,22,20,23,19,24,18,25,17,26,16,27,31,28,30,29, 33,34,32,35,47,36,46,37,45,38,44,39,43,40,42,41}; int da[] = {5,6,7,8,9,10,11,12, 21,20,19,18,17,16,31,30, 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,32, 29,28,27,26,25,24,23,22, 13,14,15,0,1,2,3,4}; int dc[] = {5,6,4,7,3,8,2,9,1,10,0,11,15,12,14,13, 21,22,20,23,19,24,18,25,17,26,16,27,31,28,30,29, 33,34,32,35,47,36,46,37,45,38,44,39,43,40,42,41}; void setup() { delay(1000); // Power-up safety delay. Serial.begin(57600); // Initialize serial port for debugging. // 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(max_bright); set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA. copy(dc, db, NUM_LEDS); } // setup() void loop() { byte currKeyState = digitalRead(BUTTON_PIN); if ((prevKeyState == LOW) && (currKeyState == HIGH)) { shortKeyPress(); } prevKeyState = currKeyState; animationA(); // render the first animation into leds2 animationB(); // render the second animation into leds3 uint8_t ratio = beatsin8(2); // Alternate between 0 and 255 every minute for (int i = 0; i < NUM_LEDS; i++) { // mix the 2 arrays together leds[dc[i]] = blend( leds2[dc[i]], leds3[dc[i]], ratio ); } FastLED.show(); } // loop() void shortKeyPress() { if ( memcmp( (const void *)dc, (const void *)da, sizeof(dc)) == 0) { copy(dc, db, NUM_LEDS); } else { copy(dc, da, NUM_LEDS); } } void animationA() { // running red stripe. for (int i = 0; i < NUM_LEDS; i++) { uint8_t red = (millis() / 5) + (i * 12); // speed, length if (red > 128) red = 0; leds2[dc[i]] = CRGB(red, 0, 0); } } // animationA() void animationB() { // running blue stripe in opposite direction. for (int i = 0; i < NUM_LEDS; i++) { uint8_t blue = (millis() / 5) - (i * 12); // speed, length if (blue > 128) blue = 0; leds3[dc[i]] = CRGB(0, 0, blue); } } // animationB() // Function to copy 'len' elements from 'src' to 'dst' void copy(int* src, int* dst, int len) { memcpy(dst, src, sizeof(src[0])*len); }