Created
October 11, 2019 00:19
-
-
Save chemdoc77/37849625902f21b6cd18cdd795e58a8c to your computer and use it in GitHub Desktop.
Meteor Shower
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Meteor Shower posted by Chemdoc77 | |
* Based on the outstanding MeteorShower sketch by Jon Burroughs as seen in Adam bluebottleyellowboxyellyfish’s clock | |
* which Chemdoc77 slightly modified. | |
*/ | |
#include <FastLED.h> | |
#define LED_PIN 6 | |
#define CHIPSET NEOPIXEL | |
#define NUM_LEDS 90 | |
#define BRIGHTNESS 100 | |
CRGB leds[NUM_LEDS]; | |
byte ledsX[NUM_LEDS][3]; | |
boolean RAINBOWs = false; | |
boolean RANDOMpick = false; | |
uint8_t hue; | |
uint16_t timeframe; | |
byte idex = 0; | |
byte colorTIP = 0; | |
byte meteorLENGTH; | |
byte loopCount = 1; //low number loop counter | |
void setup() { | |
delay(1000); // sanity delay | |
FastLED.addLeds<CHIPSET, LED_PIN>(leds, NUM_LEDS); | |
FastLED.setBrightness( BRIGHTNESS ); | |
FastLED.setMaxPowerInVoltsAndMilliamps(5,1500); | |
set_max_power_indicator_LED(13); | |
fill_solid(leds, NUM_LEDS, CRGB::Black); | |
FastLED.show(); | |
} | |
//============================================ | |
void loop() { | |
meteorShower(); | |
} | |
//=============== Functions ============== | |
void meteorShower(){ | |
//hue master | |
hue++; | |
//populate the leds[] with stored ledsX[] array data | |
for(byte i = 0; i < NUM_LEDS; i++ ) { | |
ledsX[i][0] = leds[i].r; | |
ledsX[i][1] = leds[i].g; | |
ledsX[i][2] = leds[i].b; | |
} | |
//clear the previous counter clockwise position | |
byte iCCW; | |
//we are keeping track of elapsed time | |
timeframe++; //fx timer | |
//meteorLENGTH fx is only shown for this time frame | |
if((timeframe >= 1) && (timeframe <= 280)) { meteorLENGTH = 29; } | |
if((timeframe > 280) && (timeframe <= 500)) { meteorLENGTH = 45; } | |
//RAINBOWs fx add rainbow tails during this time frame only | |
if((timeframe > 0) && (timeframe <= 280)) { RAINBOWs = true; } | |
else{ RAINBOWs = false; } | |
//keep our RAINBOWs within a specific range of hue | |
if(RAINBOWs == true){ hue = hue - 20; if(hue <= 0){ hue = 1; } } | |
//RANDOMpick fx is only enabled during this timeframe | |
if((timeframe > 600) && (timeframe <= 790)) { RANDOMpick = true; } | |
else{ RANDOMpick = false; } | |
//pick a random spot in the meteor switch case statement below | |
if (RANDOMpick == true){ idex = random8(46); } | |
else{ | |
//increment the meteor display frame | |
idex++; | |
//make sure we don't drift into space | |
if (idex > meteorLENGTH) { idex = 0; } } | |
//meteorLENGTH is randomized during this timeframe only | |
if((timeframe > 790) && (timeframe <= 1090)) { meteorLENGTH = random8(7, 38); } | |
//during this point in the animation timeframe | |
if(timeframe == 1180) { | |
//reset the timeframe | |
timeframe = 0; | |
//increment the loop counter | |
loopCount++; | |
} | |
//during this part of the loopCount, all meteors have a white colored tip | |
if(loopCount == 1) { colorTIP = 0; } | |
if(loopCount == 2) { colorTIP = 1; } | |
if(loopCount == 3) { colorTIP = random8(11); } | |
//end of the desired fx, reset the variable for the next time around | |
if(loopCount == 4) { | |
colorTIP = 0; | |
loopCount = 0; | |
} | |
//there are two switch case statements nestled into one another | |
//we always want to control the color of the meteor tip | |
//the other controls the actual meteor animation in 45 frames/case statements | |
switch (idex) { | |
case 0: | |
switch (colorTIP){ | |
case 0: | |
leds[0] = CHSV(hue, 255, 255); | |
break; | |
case 1: | |
leds[0] = CRGB(100,100,100); | |
break; | |
case 2: | |
leds[0] = CRGB::Yellow; | |
break; | |
case 3: | |
leds[0] = CRGB::Violet; | |
break; | |
case 4: | |
leds[0] = CRGB::Green; | |
break; | |
case 5: | |
leds[0] = CRGB::Purple; | |
break; | |
case 6: | |
leds[0] = CRGB::Orange; | |
break; | |
case 7: | |
leds[0] = CRGB::Cyan; | |
break; | |
case 8: | |
leds[0] = CRGB::GreenYellow; | |
break; | |
case 9: | |
leds[0] = CRGB::Magenta; | |
break; | |
case 10: | |
leds[0] = CRGB::SkyBlue; | |
} | |
break; | |
case 1: | |
leds[0] = CHSV((hue - 20), 255, 210); | |
break; | |
case 2: | |
leds[0] = CHSV((hue - 22), 255, 180); | |
break; | |
case 3: | |
leds[0] = CHSV((hue - 23), 255, 150); | |
break; | |
case 4: | |
leds[0] = CHSV((hue - 24), 255, 110); | |
break; | |
case 5: | |
leds[0] = CHSV((hue - 25), 255, 90); | |
break; | |
case 6: | |
leds[0] = CHSV((hue - 26), 160, 60); | |
break; | |
case 7: | |
leds[0] = CHSV((hue - 27), 140, 40); | |
break; | |
case 8: | |
leds[0] = CHSV((hue - 28), 120, 20); | |
break; | |
case 9: | |
leds[0] = CHSV((hue - 29), 100, 20); | |
break; | |
case 10: | |
leds[0] = CRGB::Black; | |
break; | |
case 11: | |
leds[0] = CRGB::Black; | |
break; | |
case 12: | |
leds[0] = CRGB::Black; | |
break; | |
case 13: | |
leds[0] = CRGB::Black; | |
break; | |
case 14: | |
leds[0] = CRGB::Black; | |
break; | |
case 15: | |
leds[0] = CRGB::Black; | |
break; | |
case 16: | |
leds[0] = CRGB::Black; | |
break; | |
case 17: | |
leds[0] = CRGB::Black; | |
break; | |
case 18: | |
leds[0] = CRGB::Black; | |
break; | |
case 19: | |
leds[0] = CRGB::Black; | |
break; | |
case 20: | |
leds[0] = CRGB::Black; | |
break; | |
case 21: | |
leds[0] = CRGB::Black; | |
break; | |
case 22: | |
leds[0] = CRGB::Black; | |
break; | |
case 23: | |
leds[0] = CRGB::Black; | |
break; | |
case 24: | |
leds[0] = CRGB::Black; | |
break; | |
case 25: | |
leds[0] = CRGB::Black; | |
break; | |
case 26: | |
leds[0] = CRGB::Black; | |
break; | |
case 27: | |
leds[0] = CRGB::Black; | |
break; | |
case 28: | |
leds[0] = CRGB::Black; | |
break; | |
case 29: | |
leds[0] = CRGB::Black; | |
break; | |
case 30: | |
leds[0] = CRGB::Black; | |
break; | |
case 31: | |
leds[0] = CRGB::Black; | |
break; | |
case 32: | |
leds[0] = CRGB::Black; | |
break; | |
case 33: | |
leds[0] = CRGB::Black; | |
break; | |
case 34: | |
leds[0] = CRGB::Black; | |
break; | |
case 35: | |
leds[0] = CRGB::Black; | |
break; | |
case 36: | |
leds[0] = CRGB::Black; | |
break; | |
case 37: | |
leds[0] = CRGB::Black; | |
break; | |
case 38: | |
leds[0] = CRGB::Black; | |
break; | |
case 39: | |
leds[0] = CRGB::Black; | |
break; | |
case 40: | |
leds[0] = CRGB::Black; | |
break; | |
case 41: | |
leds[0] = CRGB::Black; | |
break; | |
case 42: | |
leds[0] = CRGB::Black; | |
break; | |
case 43: | |
leds[0] = CRGB::Black; | |
break; | |
case 44: | |
leds[0] = CRGB::Black; | |
break; | |
case 45: | |
leds[0] = CRGB::Black; | |
break; | |
} | |
//copy the LED Array | |
for(byte i = 1; i < NUM_LEDS; i++ ) { | |
iCCW = adjacent_ccw(i); | |
leds[i].r = ledsX[iCCW][0]; | |
leds[i].g = ledsX[iCCW][1]; | |
leds[i].b = ledsX[iCCW][2]; | |
} | |
//show the blinky | |
FastLED.show(); | |
//control the animation speed/frame rate | |
delay(30); | |
} | |
//find the adjacent counter clockwise postion of the led | |
//funkboxing code snippet | |
byte adjacent_ccw(byte i) { | |
byte r; | |
if (i > 0) { r = i - 1; } | |
else { r = NUM_LEDS - 1; } | |
return r; | |
} |
camperLou
commented
Jul 24, 2024
via email
Still experiencing non-functioning reverse order.
void meteorShower()
{
//hue master
hue++;
//populate the leds[] with stored ledsX[] array data
// for(byte i = 0; i < NUM_LEDS; i++ ) { // original code // "Only"
led[0] is flashing
for (int i = (NUM_LEDS - 1); i > 0; i-- ) {
ledsX[i][0] = leds[i].r;
ledsX[i][1] = leds[i].g;
ledsX[i][2] = leds[i].b;
}
Change other variables from "byte" to "int" as byte is 8bit and int is
16bit with no success.
The only led illuminating is led[0] which seems to correspond to the
original code.
I have attached my edited version of your code...perhaps you can see or
suggest things to try.
Other changes:
#include "ESPTrueRandom.h"
#include "FastLED.h"
#define DATA_PIN D5
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 50
#define BRIGHTNESS 80
CRGB leds[NUM_LEDS];
I don't know what module you originally used--currently using WeMOS esp8266
with plans of using esp32.
Thank you
Louis Hall
…On Thu, Jul 18, 2024 at 9:08 AM chemdoc77 ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi Louis:
Thank you for your interest in my code. I would be interested in seeing
your final code using WiFI.
I am busy with chemistry courses that I am now teaching.
I will have some time this Sunday to look at your request and see what
changes are needed to change the direction of the lights.
Best Regards,
Chemdoc77
(AKA Ken)
On Tue, Jul 16, 2024 at 6:49 PM camperLou ***@***.***> wrote:
> ***@***.**** commented on this gist.
> ------------------------------
>
> Found this code to be incredible...and changed to match esp32 using wifi.
> Would like to change the direction 180 so that the leds begin their
travel
> from the "end" of the strip as compared to the current led[0] position. I
> have tried tweaking LINE:85 (byte i = 0; i < NUM_LEDS; i++ ) with for
(int
> i = (NUM_LEDS - 1); i >= 0; i--) with no success. Can yo help...thanks!
>
> Louis Hall
>
> —
> Reply to this email directly, view it on GitHub
> <
https://gist.github.com/chemdoc77/37849625902f21b6cd18cdd795e58a8c#gistcomment-5123643
>
> or unsubscribe
> <
https://github.com/notifications/unsubscribe-auth/ABHLGTLDJIWOQWGXHPDRWLTZMWWQJBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA4TQOBRGA2TAONHORZGSZ3HMVZKMY3SMVQXIZI
>
> .
> You are receiving this email because you authored the thread.
>
> Triage notifications on the go with GitHub Mobile for iOS
> <
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
>
> or Android
> <
https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub
>
> .
>
>
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/chemdoc77/37849625902f21b6cd18cdd795e58a8c#gistcomment-5125553>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMB5TXCP2AGLTIXDGMRQAP3ZM6433BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVA4TQOBRGA2TAONHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment