Guest User

Untitled

a guest
Nov 23rd, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. #include "FastSPI_LED2.h"
  2. #define NUM_LEDS 16
  3. #define DATA_PIN 3
  4.  
  5. CRGB leds[NUM_LEDS];
  6.  
  7. // LED FX VARS
  8. WS2811Controller800Khz<DATA_PIN, GRB> ledController;
  9.  
  10. int ihue = 0;
  11. void setup() {
  12.   FastLED.addLeds(&ledController, leds, NUM_LEDS);
  13.   random16_set_seed(analogRead(0));
  14. }
  15.  
  16. void loop() {
  17.   flame(300);
  18.   rainbow_loop(5,30,128);
  19.   int fhue = random8(255);
  20.   flicker(fhue,255,300);
  21.   simpleWave(983,39,10, fhue);
  22.  
  23. }
  24. void simpleWave(int rate,int cycles,int wait, int hue) {
  25.    int pos = 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.       int level = 128 + (sin16((i*10430)+pos) / 256);
  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 = random8(0,255);
  46.     int random_delay = random8(10,100);
  47.     int random_bool = random8(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.     uint16_t hmin = 0; uint16_t hmax = 45 * 256;
  69.     uint16_t hdif = hmax-hmin;
  70.     int randtemp = random8(0,3) * 256;
  71.     int rtop = random8(10,NUM_LEDS);
  72.     int hinc = (hdif/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/256, 255, 255);  
  78.       leds[rtop].r = 255; leds[rtop].g = 255; leds[rtop].b = 255;    
  79.  
  80.     }
  81.     FastLED.show();  
  82.     int idelay = random8(20,50);    
  83.     delay(idelay);
  84.   }  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment