Guest User

Untitled

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