/* sinelon * * By: Mark Kriegsman * * Modified by: Andrew Tuline * * Date: February 2015 * * This uses the built in beat in FastLED to move a dot back and forth. In this case, it uses two beats added together for more randomness. * */ #include "FastLED.h" // FastLED library. Preferably the latest copy of FastLED 2.1. #if FASTLED_VERSION < 3001000 #error "Requires FastLED 3.1 or later; check github for latest code." #endif // Fixed definitions cannot change on the fly. #define LED_DT 12 // Data pin to connect to the strip. #define LED_CK 11 // Clock pin for WS2801 or APA102. #define COLOR_ORDER BGR // It's GRB for WS2812 and BGR for APA102. #define LED_TYPE APA102 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit. #define NUM_LEDS 60 // Number of LED's. // Global variables can be changed on the fly. uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. struct CRGB leds[NUM_LEDS]; // Initialize our LED array. CRGBPalette16 currentPalette; CRGBPalette16 targetPalette; TBlendType currentBlending; // NOBLEND or LINEARBLEND // Define variables used by the sequences. uint8_t thisbeat = 23; // Beats per minute for first part of dot. uint8_t thatbeat = 28; // Combined the above with this one. uint8_t thisfade = 32; // How quickly does it fade? Lower = slower fade rate. uint8_t thissat = 255; // The saturation, where 255 = brilliant colours. uint8_t thisbri = 255; // Brightness of a sequence. int myhue = 0; int thisdelay = 50; void setup() { Serial.begin(57600); // Initialize serial port for debugging. delay(1000); // Soft startup to ease the flow of electrons. // LEDS.addLeds(leds, NUM_LEDS); // Use this for WS2812B LEDS.addLeds(leds, NUM_LEDS); // Use this for WS2801 or APA102 currentBlending = LINEARBLEND; FastLED.setBrightness(max_bright); set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA. } // setup() void loop () { EVERY_N_MILLISECONDS(100) { uint8_t maxChanges = 24; nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability. } EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds. static uint8_t baseC = random8(); // You can use this as a baseline colour if you want similar hues in the next line. targetPalette = CRGBPalette16(CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 255, random8(128,255)), CHSV(random8(), 192, random8(128,255)), CHSV(random8(), 255, random8(128,255))); } EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence. sinelon(); // Call our sequence. } FastLED.show(); } // loop() void sinelon() { // a colored dot sweeping back and forth, with fading trails fadeToBlackBy( leds, NUM_LEDS, thisfade); int pos1 = beatsin16(thisbeat,0,NUM_LEDS); int pos2 = beatsin16(thatbeat,0,NUM_LEDS); leds[(pos1+pos2)/2] += ColorFromPalette(currentPalette, myhue++, thisbri, currentBlending); } // sinelon()