Guest User

Meteor_coded_by_Roy_3

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