Created
August 8, 2018 19:58
-
-
Save nervusvagus/2f6b8278ea192e4f248ca2136206ca9a to your computer and use it in GitHub Desktop.
mover example using 101% of Arduino Nano memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* mover- | |
By: Andrew Tuline | |
Date: February 2015 | |
This is a simple pixel moving routine for those of you that just like to count pixels on a strand. | |
I prefer to use sine waves as they provide a LOT of flexibility with less code for moving pixels around. | |
You should be able to add more variables, such as hues, hue rotation, direction and so forth. | |
*/ | |
#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 10 // 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 255 // Number of LED's. | |
// Initialize changeable global variables. | |
uint8_t max_bright = 128; // Overall brightness definition. It can be changed on the fly. | |
struct CRGB leds[NUM_LEDS]; // Initialize our LED array. | |
struct CRGB base[NUM_LEDS]; | |
// Define variables used by the sequence. | |
uint8_t thisdelay = 10; // A delay value for the sequence(s). | |
uint8_t thisfade = 192; // How quickly does it fade? Lower = slower fade rate. | |
void setup() { | |
delay(1000); // Power-up safety delay or something like that. | |
Serial.begin(57600); | |
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // Use this for WS2812B | |
FastLED.addLeds<WS2812, 10, GRB>(leds, 300); | |
FastLED.setBrightness(max_bright); | |
set_max_power_in_volts_and_milliamps(5, 500); // FastLED power management set at 5V, 500mA. | |
} // setup() | |
void loop () { | |
// Check the demo loop for changes to the variables. | |
mover(); | |
// JellyFishBase();// Call our sequence. | |
} // loop() | |
void JellyFishBase(){ | |
fill_solid( base, NUM_LEDS, CRGB::Red); // base color | |
} | |
void mover() { | |
static uint8_t hue = 0; | |
for (int i = 0; i < NUM_LEDS; i++) { | |
leds[i] += CRGB::Blue; | |
leds[(i+1) % NUM_LEDS] += CRGB::Green; // We use modulus so that the location is between 0 and NUM_LEDS | |
leds[(i+2) % NUM_LEDS] += CRGB::Green; // Same here. | |
leds[(i+3) % NUM_LEDS] += CRGB::Green; // Same here. | |
leds[(i+5) % NUM_LEDS] += CRGB::Green; // Same here. | |
leds[(i+6) % NUM_LEDS] += CRGB::Green; | |
leds[(i+7) % NUM_LEDS] += CRGB::Green; | |
leds[(i+8) % NUM_LEDS] += CRGB::Green; | |
leds[(i+9) % NUM_LEDS] += CHSV( 90, 255, 255); | |
leds[(i+10) % NUM_LEDS] += CHSV( 90, 255, 255); | |
leds[(i+11) % NUM_LEDS] += CHSV( 60, 255, 255); | |
leds[(i+12) % NUM_LEDS] += CHSV( 60, 255, 255); | |
leds[(i+13) % NUM_LEDS] += CHSV( 60, 255, 255); | |
leds[(i+14) % NUM_LEDS] += CHSV( 60, 255, 255); | |
leds[(i+15) % NUM_LEDS] += CHSV( 60, 255, 255); | |
leds[(i+16) % NUM_LEDS] += CHSV( 30, 255, 255); | |
leds[(i+17) % NUM_LEDS] += CHSV( 30, 255, 255); | |
show_at_max_brightness_for_power(); | |
fadeToBlackBy(leds, NUM_LEDS, thisfade); // Low values = slower fade. | |
delay(thisdelay); // UGH!!!! A blocking delay. If you want to add controls, they may not work reliably. | |
} | |
} // mover() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment