85 lines
2.9 KiB
C++
85 lines
2.9 KiB
C++
/* 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.
|
|
|
|
#if FASTLED_VERSION < 3001000
|
|
#error "Requires FastLED 3.1 or later; check github for latest code."
|
|
#endif
|
|
|
|
#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 change LEDS.addLeds.
|
|
#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.
|
|
|
|
// 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];
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
delay(1000); // Power-up safety delay.
|
|
Serial.begin(57600); // Initialize serial port for debugging.
|
|
|
|
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102
|
|
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812
|
|
|
|
FastLED.setBrightness(max_bright);
|
|
set_max_power_in_volts_and_milliamps(5, 500); // FastLED Power management set at 5V, 500mA.
|
|
|
|
} // setup()
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
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[i] = blend( leds2[i], leds3[i], ratio );
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
} // loop()
|
|
|
|
|
|
|
|
void animationA() { // running red stripe.
|
|
|
|
for (int i = 0; i < NUM_LEDS; i++) {
|
|
uint8_t red = (millis() / 10) + (i * 12); // speed, length
|
|
if (red > 128) red = 0;
|
|
leds2[i] = CRGB(red, 0, 0);
|
|
}
|
|
} // animationA()
|
|
|
|
|
|
|
|
void animationB() { // running green stripe in opposite direction.
|
|
for (int i = 0; i < NUM_LEDS; i++) {
|
|
uint8_t green = (millis() / 5) - (i * 12); // speed, length
|
|
if (green > 128) green = 0;
|
|
leds3[i] = CRGB(0, green, 0);
|
|
}
|
|
} // animationB()
|