Advertisement
Guest User

Beambox - Fade Whole Tower Rainbow

a guest
May 27th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. /*
  2.  
  3. //---BEAMBOX---//
  4. The controllable Light Tower!
  5. Code by PerfectPixel
  6. Instructable at: http://www.instructables.com/id/BeamBox-A-tower-that-glows-to-your-commands/
  7. //-------------//
  8. Feel free to copy this code and do what you like with it, no credit necessary!!
  9.  
  10. */
  11. #include "FastLED.h"
  12. int r = 255; // To start the fading at a particular color, simply input that color here!
  13. int g = 0;
  14. int b = 0;
  15. int i = 0;
  16.  
  17. #define NUM_LEDS 7 //Change this to the number of LEDs in your tower
  18. #define DATA_PIN 9 //This is the pin that the LEDs are on
  19. CRGB leds[NUM_LEDS];
  20.  
  21. void setup(){
  22.     delay(2000);
  23.  
  24.       // !!! Uncomment one of the following lines for your leds arrangement: !!! //
  25.      
  26.       // FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
  27.       // FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
  28.       // FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
  29.       FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
  30.       // FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
  31.       // FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
  32.       // FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  33.       // FastLED.addLeds<WS2811_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  34.       // FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
  35.       // FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
  36.       // FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
  37.       // FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
  38.  
  39.       // FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
  40.       // FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
  41.       // FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
  42.       // FastLED.addLeds<P9813, RGB>(leds, NUM_LEDS);
  43.      
  44.       // FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  45.       // FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  46.       // FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
  47. }
  48.  
  49. void loop() {
  50.   if(r > 0 && b == 0){ //This bit does the fading for you
  51.     r--;
  52.     g++;
  53.   }
  54.   if(g > 0 && r == 0){
  55.     g--;
  56.     b++;
  57.   }
  58.   if(b > 0 && g == 0){
  59.     r++;
  60.     b--;
  61.   }
  62.   for(i = 0; i < NUM_LEDS; i++){
  63.       leds[i].setRGB( r, g, b); //Sets the values of the LEDs.
  64.   }
  65.       FastLED.show();
  66.       delay(100);  //Change this to determine the speed of the fading
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement