Guest User

Untitled

a guest
Nov 23rd, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "FastSPI_LED2.h"
  2.  
  3. #define NUM_LEDS 16
  4. #define DATA_PIN 1
  5.  
  6. CRGB leds[NUM_LEDS];
  7.  
  8. // LED FX VARS
  9.  
  10. int ihue = 0;
  11. void setup() {
  12.   FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  13.   randomSeed(analogRead(0));
  14. }
  15.  
  16. void loop() {
  17.   flame(300);
  18.   rainbow_loop(5,30,128);
  19.   int fhue = random(255);
  20.   flicker(fhue,255,300);
  21.   simpleWave(0.03,39,10, fhue);
  22.  
  23. }
  24. void simpleWave(float rate,int cycles,int wait, int hue) {
  25.    float pos = 0.0;
  26.    for(int x=0; x<(NUM_LEDS*cycles); x++) {
  27.     pos = pos+rate;
  28.    
  29.     for (int i=0; i<NUM_LEDS;i++) {
  30.       float level = sin(i+pos) * 127 + 128;
  31.       leds[i] = CHSV(hue,255,level);
  32.     }
  33.  
  34.     FastLED.show();
  35.     delay(wait);
  36.   }
  37. }
  38.  
  39. void pacman(int reps, int wait) {
  40.   // pacman inspired animation - start yellow, moves towards power-pellet at top
  41.  
  42. }
  43. void flicker(int thishue, int thissat, int reps) {            //-m9-FLICKER EFFECT
  44.   for (int q = 0; q<=reps; q++) {
  45.     int random_bright = random(0,255);
  46.     int random_delay = random(10,100);
  47.     int random_bool = random(0,random_bright);
  48.     if (random_bool < 10) {
  49.       for(int i = 0 ; i < NUM_LEDS; i++ ) {
  50.         leds[i] = CHSV(thishue, thissat, random_bright);
  51.       }
  52.       FastLED.show();    
  53.       delay(random_delay);
  54.     }
  55.   }
  56. }
  57. void rainbow_loop(int istep, int idelay, int reps) {
  58.   for (int q=0;q<reps;q++) {
  59.  
  60.     ihue = ihue+istep;
  61.     fill_rainbow(&leds[0],NUM_LEDS,ihue);
  62.     FastLED.show();
  63.     delay(idelay);
  64.   }
  65. }  
  66. void flame(int reps) {  
  67.   for(int q=0; q<reps; q++){
  68.     float hmin = 0.1; float hmax = 45.0;
  69.     float hdif = hmax-hmin;
  70.     int randtemp = random(0,3);
  71.     int rtop = random(10,NUM_LEDS);
  72.     float hinc = (hdif/float(rtop))+randtemp;
  73.     int ihue = hmin;
  74.     fill_solid(&leds[0],NUM_LEDS,CHSV(0,0,0));
  75.     for(int i = 0; i < rtop; i++ ) {
  76.       ihue = ihue + hinc;
  77.       leds[i] = CHSV(ihue, 255, 255);  
  78.       leds[rtop].r = 255; leds[rtop].g = 255; leds[rtop].b = 255;    
  79.  
  80.     }
  81.     FastLED.show();  
  82.     int idelay = random(20,50);    
  83.     delay(idelay);
  84.   }  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment