Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 2
- #define NUM_LEDS 255 //max # of leds for this code
- CRGB leds[NUM_LEDS];
- byte temp[NUM_LEDS];
- byte wave;
- int wave_scale = 20;
- unsigned long currentMillis,previousMillis = 0;
- void setup(){
- //be sure to add your leds
- FastLED.addLeds< NEOPIXEL, LED_PIN >(leds, NUM_LEDS);
- setup_hue_array();
- }
- void loop(){
- wave_fx();
- }
- void wave_fx(){
- //define the middle of the strip
- static byte middle = NUM_LEDS/2;
- //check the millis() timer
- currentMillis = millis();
- //if enough time has passed, run the program
- if(currentMillis - previousMillis >= 10) {
- for (byte i = 0; i < middle; i++){
- //this is the function that creates the wave effect
- //it may take time to fully understand what is happening here
- wave = sin8((millis() / wave_scale) * i);
- //populate the leds[x] with the temp[x] array hue's
- leds[i] = CHSV(temp[i], 255, wave);
- }
- //now mirror the data from leds #0 thru #middle
- //to leds #middle thru #end of string
- for(byte i = middle; i < NUM_LEDS; i++){
- leds[i] = leds[NUM_LEDS - i];
- }
- //timestamp the animation and show the leds[] data
- previousMillis = currentMillis;
- LEDS.show();
- }
- }
- void setup_hue_array(){
- static byte x, hue = 0;
- //only assign data for half the led strip
- for(byte i = 0; i < ((NUM_LEDS/2)+ 1); i++){
- //for every 5 leds, increase the hue by 20
- if(x++ == 5){
- hue += 20;
- x = 0;
- }
- //assign the hue for later use in the temp[] array
- temp[i] = hue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment