prouton

Simpler Meteor Shower for FastLED

Dec 12th, 2014
2,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. /*
  2. By: Peter Routon
  3. Date: December 2014
  4. This is my adaptation and simplification (i.e., reduced options) of meteorShower, Jon Burroughs' adaptation
  5. of some funkboxing code from Thomas Eldridge.
  6. */
  7. //================================================
  8. #include "FastLED.h"
  9. #define LED_COUNT 15
  10. #define LED_PIN 12
  11. struct CRGB leds[LED_COUNT];
  12. //================================================
  13.  
  14. uint8_t hue = 32;
  15. byte idex = 255;
  16. byte meteorLength = 29;
  17.  
  18. void setup() {
  19. // sanity check delay - allows reprogramming if accidently blowing power w/leds
  20. delay(2000);
  21. LEDS.addLeds<WS2812, LED_PIN, GRB>(leds, LED_COUNT);
  22. LEDS.setBrightness(200);
  23. }
  24.  
  25. void loop(){
  26. meteorShower();
  27. }
  28.  
  29. void meteorShower(){
  30. // slide all the pixels down one in the array
  31. memmove8( &leds[1], &leds[0], (LED_COUNT - 1) * 3 );
  32.  
  33. // increment the meteor display frame
  34. idex++;
  35. // make sure we don't drift into space
  36. if ( idex > meteorLength ) {
  37. idex = 0;
  38. // cycle through hues in each successive meteor tail
  39. hue += 32;
  40. }
  41.  
  42. // this switch controls the actual meteor animation, i.e., what gets placed in the
  43. // first position and then subsequently gets moved down the strip by the memmove above
  44. switch ( idex ) {
  45. case 0:
  46. leds[0] = CRGB(200,200,200);
  47. break;
  48. case 1:
  49. leds[0] = CHSV((hue - 20), 255, 210);
  50. break;
  51. case 2:
  52. leds[0] = CHSV((hue - 22), 255, 180);
  53. break;
  54. case 3:
  55. leds[0] = CHSV((hue - 23), 255, 150);
  56. break;
  57. case 4:
  58. leds[0] = CHSV((hue - 24), 255, 110);
  59. break;
  60. case 5:
  61. leds[0] = CHSV((hue - 25), 255, 90);
  62. break;
  63. case 6:
  64. leds[0] = CHSV((hue - 26), 160, 60);
  65. break;
  66. case 7:
  67. leds[0] = CHSV((hue - 27), 140, 40);
  68. break;
  69. case 8:
  70. leds[0] = CHSV((hue - 28), 120, 20);
  71. break;
  72. case 9:
  73. leds[0] = CHSV((hue - 29), 100, 20);
  74. break;
  75. default:
  76. leds[0] = CRGB::Black;
  77. }
  78.  
  79. // show the blinky
  80. FastLED.show();
  81. // control the animation speed/frame rate
  82. delay(30);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment