Advertisement
Guest User

Untitled

a guest
Nov 4th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define LED_PIN 9
  4. #define LED_TYPE WS2812B
  5. #define COLOR_ORDER GRB
  6. #define NUM_LEDS 48
  7. CRGB leds[NUM_LEDS];
  8. int location =0;
  9. unsigned long time;
  10.  
  11. void setup() {
  12. FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS);
  13. time=millis();
  14. }
  15.  
  16. void loop()
  17. {
  18. if (millis()>=time) { // update leds every 10ms(=50hz)
  19. time=time+10;
  20. chase();
  21. }
  22. }
  23.  
  24. void chase()
  25. {
  26. if (location==255) location=0;
  27. location=location+1;
  28. CHSV start_col = CHSV(location, 255, 255);
  29. CHSV end_col = CHSV(255+location, 255, 255);
  30. fill_gradient(leds,0,end_col,NUM_LEDS,start_col,BACKWARD_HUES);
  31. int brightest=location/255.0*NUM_LEDS;
  32. for (byte w=0;w<NUM_LEDS;w++) {
  33. leds[brightest].fadeLightBy(w*5.3);
  34. brightest=brightest-1;
  35. if (brightest<0) brightest=NUM_LEDS;
  36. }
  37. FastLED.show();
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement