Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define COLOR_ORDER GRB
- #define NUM_STRIPS 3
- #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 = 4;
- void setup(){
- delay(3000);
- FastLED.addLeds<WS2811, 2, GRB>(leds[0], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<WS2811, 14, GRB>(leds[1], NUM_LEDS_PER_STRIP);
- FastLED.addLeds<WS2811, 7, GRB>(leds[2], NUM_LEDS_PER_STRIP);
- for (int j=0; j<NUM_LEDS_PER_STRIP; j++){
- Meteor_position[j] = 0;
- for (int i=0; i<NUM_STRIPS; i++){
- leds[i][j] = CRGB(0,0,0);
- }
- }
- }
- 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] < 48){ // 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();
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement