Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* blend
- By: Andrew Tuline
- Date: June, 2015
- Here's a simple method to blend between a couple of colours across a strand of LED's. It doesn't really make good use of
- the individually addressable aspect of these LED's.
- It uses FastLED's:
- - blend() function to blend between two colours
- - sin8() function to provide a smooth varying input to blend().
- */
- #include "FastLED.h" // FastLED library. Preferably the latest copy of FastLED 2.1.
- // Fixed global definitions.
- #define LED_DT 12 // Data pin to connect to the strip.
- #define LED_CK 11
- #define COLOR_ORDER BGR // Are they RGB, GRB or what??
- #define LED_TYPE APA102 // Don't forget to change LEDS.addLeds
- #define NUM_LEDS 20 // Number of LED's.
- // Initialize changeable global variables.
- uint8_t max_bright = 16; // Overall brightness definition. It can be changed on the fly.
- struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
- // Define variables used by the sequence.
- uint8_t thisdelay = 25; // Our delay.
- int mysine=0; // Input for a sinewave. Saves on counting up/down.
- void setup() {
- delay(1000); // Power-up safety delay or something like that.
- Serial.begin(57600);
- LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2801 or APA102
- FastLED.setBrightness(max_bright);
- } // setup()
- void loop () {
- blendme();
- FastLED.show();
- delay(thisdelay);
- mysine++;
- } // loop()
- void blendme() {
- for (uint8_t i = 0; i<NUM_LEDS; i++) {
- leds[i] = blend(CRGB::Red, CRGB::Blue, sin8(mysine));
- // If you forgot about the blend function, you can always use this instead:
- // leds[i].r = sin8(mysine);
- // leds[i].b = 255 - sin8(mysine);
- }
- } // blendme()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement