Guest User

Meteor_coded_by_Roy

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