Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* inoise8_mover
- *
- * By: Andrew Tuline
- *
- * Date: February, 2017
- *
- * We've used sine waves and counting to move pixels around a strand. In this case, I'm using Perlin Noise to move a pixel up and down the strand.
- *
- * The advantage here is that it provides random natural movement without requiring lots of fancy math by joe programmer.
- *
- */
- #include "FastLED.h"
- #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 GRB // It's GRB for WS2812 and BGR for APA102.
- #define LED_TYPE WS2812 // Using APA102, WS2812, WS2801. Don't forget to modify LEDS.addLeds to suit.
- #define NUM_LEDS 40 // 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];
- CRGBPalette16 currentPalette=LavaColors_p;
- CRGBPalette16 targetPalette=OceanColors_p;
- TBlendType currentBlending; // NOBLEND or LINEARBLEND
- void setup() {
- Serial.begin(115200); // Initialize serial port for debugging.
- delay(1000); // Soft startup to ease the flow of electrons.
- LEDS.addLeds<LED_TYPE,LED_DT,COLOR_ORDER>(leds,NUM_LEDS);
- // LEDS.addLeds<LED_TYPE,LED_DT,LED_CK, COLOR_ORDER>(leds,NUM_LEDS);
- FastLED.setBrightness(max_bright);
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 500); // FastLED Power management set at 5V, 500mA.
- } // setup()
- void loop() {
- inoise8_mover();
- fadeToBlackBy(leds, NUM_LEDS, 4); // Update the LED array with noise at the new location
- EVERY_N_MILLISECONDS(10) {
- nblendPaletteTowardPalette(currentPalette, targetPalette, 24); // AWESOME palette blending capability.
- }
- EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds.
- 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)));
- }
- FastLED.show();
- } // loop()
- void inoise8_mover() {
- static uint16_t dist;
- for (int i=0; i<3; i++) {
- uint8_t locn = inoise8(millis()*8/64+i*500, millis()*8/64); // Get a new pixel location from moving noise.
- uint8_t pixlen = map(locn,50,192,0,NUM_LEDS-1)%(NUM_LEDS-1); // Map that to the length of the strand, and ensure we don't go over.
- leds[pixlen] = ColorFromPalette(currentPalette, pixlen, 255, LINEARBLEND); // Use that value for both the location as well as the palette index colour for the pixel.
- }
- } // inoise8_mover()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement