Guest User

Meteor_coded_by_Roy_2

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