Advertisement
Guest User

Meteors with 3 strips

a guest
Feb 27th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define COLOR_ORDER GRB
  4. #define NUM_STRIPS 3
  5. #define NUM_LEDS_PER_STRIP 15
  6.  
  7. CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
  8. uint8_t Meteor_position[NUM_LEDS_PER_STRIP];
  9. uint8_t Meteor_color[NUM_LEDS_PER_STRIP];
  10. uint8_t Meteor_speed = 1;
  11. uint8_t Meteor_fade = 4;
  12.  
  13. void setup(){
  14.  
  15. delay(3000);
  16.  
  17. FastLED.addLeds<WS2811, 2, GRB>(leds[0], NUM_LEDS_PER_STRIP);
  18. FastLED.addLeds<WS2811, 14, GRB>(leds[1], NUM_LEDS_PER_STRIP);
  19. FastLED.addLeds<WS2811, 7, GRB>(leds[2], NUM_LEDS_PER_STRIP);
  20.  
  21.  
  22. for (int j=0; j<NUM_LEDS_PER_STRIP; j++){
  23. Meteor_position[j] = 0;
  24. for (int i=0; i<NUM_STRIPS; i++){
  25. leds[i][j] = CRGB(0,0,0);
  26. }
  27. }
  28. }
  29.  
  30. void loop(){
  31.  
  32. random16_add_entropy( random());
  33. for (int column = 0; column < NUM_LEDS_PER_STRIP; column++){
  34. if (Meteor_position[column] > 0){ // If there is currently a meteor
  35. //in that column, update it's position
  36. Meteor_position[column] += Meteor_speed;
  37. }
  38. else if (random16() < 65){ // If there is no meteor, give it
  39. //~20% chance of a new meteor starting ! Needs revision for 300 LEDs !
  40. Meteor_position[column] += Meteor_speed;
  41. Meteor_color[column] = random8(25); // Random color selection for a new
  42. //meteor. Will select mostly white colored meteors
  43. }
  44.  
  45. else continue; // No need to update any meteor on
  46. //the current column so continue direct to the next x column
  47.  
  48. if (Meteor_position[column] < 48){ // Update pixel only if it is the
  49. //first time through the 8 pixels
  50. uint8_t pixel_fraction = (Meteor_position[column] & 0x0F) * 16; // extract
  51. //the 'factional' part of the meteor position
  52. uint8_t pixel = (Meteor_position[column] & 0x70) / 16; // extract
  53. //the raw pixel number from the meteor position
  54.  
  55. switch(Meteor_color[column]){
  56. case 0:
  57. leds[pixel][column] = CRGB(pixel_fraction,0,0);
  58. break;
  59. case 1:
  60. leds[pixel][column] = CRGB(0,pixel_fraction,0);
  61. break;
  62. case 2:
  63. leds[pixel][column] = CRGB(0,0,pixel_fraction);
  64. break;
  65. case 3:
  66. leds[pixel][column] = CRGB(pixel_fraction,pixel_fraction,0);
  67. break;
  68. case 4:
  69. leds[pixel][column] = CRGB(0,pixel_fraction,pixel_fraction);
  70. break;
  71. case 5:
  72. leds[pixel][column] = CRGB(pixel_fraction,0,pixel_fraction);
  73. break;
  74. default:
  75. leds[pixel][column] = CRGB(pixel_fraction,pixel_fraction,pixel_fraction);
  76. break;
  77. }
  78. }
  79. }
  80. for (int i=0; i<NUM_STRIPS; i++){
  81. for (int j=0; j<NUM_LEDS_PER_STRIP; j++){
  82. leds[i][j] -= CRGB(Meteor_fade,Meteor_fade,Meteor_fade);
  83. }
  84. }
  85. FastLED.show();
  86. delay(10);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement