Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_STRIPS 8
- #define NUM_LEDS_PER_STRIP 15
- CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];
- uint8_t Meteor_position[NUM_LEDS_PER_STRIP];
- uint8_t Meteor_color[NUM_LEDS_PER_STRIP];
- uint8_t Meteor_speed = 1;
- uint8_t Meteor_fade = 2;
- void setup(){
- for (int i=0; i<NUM_STRIPS; i++){
- for (int j=0; j<NUM_LEDS_PER_STRIP; j++){
- leds[i][j] = CRGB(0,0,0);
- for (int k=0; k<NUM_LEDS_PER_STRIP; k++){
- Meteor_position[k] = 0;
- }
- }
- //and here is my complete main loop:
- //Note there is no other functions but the main loop !!
- void loop();
- random16_add_entropy( random());
- for (int column = 0; column < NUM_LEDS_PER_STRIP; column++){
- if (Meteor_position[column] > 0){ // If there is currently a meteor
- //in that column, update it's position
- Meteor_position[column] += Meteor_speed;
- }
- else if (random16() < 65){ // If there is no meteor, give it
- //~20% chance of a new meteor starting ! Needs revision for 300 LEDs !
- Meteor_position[column] += Meteor_speed;
- Meteor_color[column] = random8(25); // Random color selection for a new
- //meteor. Will select mostly white colored meteors
- }
- else continue; // No need to update any meteor on
- //the current column so continue direct to the next x column
- if (Meteor_position[column] < 128){ // Update pixel only if it is the
- //first time through the 8 pixels
- uint8_t pixel_fraction = (Meteor_position[column] & 0x0F) * 16; // extract
- //the 'factional' part of the meteor position
- uint8_t pixel = (Meteor_position[column] & 0x70) / 16; // extract
- //the raw pixel number from the meteor position
- switch(Meteor_color[column]){
- case 0:
- leds[pixel][column] = CRGB(pixel_fraction,0,0);
- break;
- case 1:
- leds[pixel][column] = CRGB(0,pixel_fraction,0);
- break;
- case 2:
- leds[pixel][column] = CRGB(0,0,pixel_fraction);
- break;
- case 3:
- leds[pixel][column] = CRGB(pixel_fraction,pixel_fraction,0);
- break;
- case 4:
- leds[pixel][column] = CRGB(0,pixel_fraction,pixel_fraction);
- break;
- case 5:
- leds[pixel][column] = CRGB(pixel_fraction,0,pixel_fraction);
- break;
- default:
- leds[pixel][column] = CRGB(pixel_fraction,pixel_fraction,pixel_fraction);
- break;
- }
- }
- }
- for (int i=0; i<NUM_STRIPS; i++){
- for (int j=0; j<NUM_LEDS_PER_STRIP; j++){
- leds[i][j] -= CRGB(Meteor_fade,Meteor_fade,Meteor_fade);
- }
- }
- FastLED.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment