Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_LEDS 100
- CRGB leds[NUM_LEDS];
- #define PIN 14
- #define TWINKLE_LOOP 2 //ここを変えるとTWINKLE_LOOP*約11秒の演出に 想定では音楽が掛かていない状態のアニメーション
- #define METEOR_RAIN_LOOP 7//ここを変えると*6秒の演出に 想定では音楽が掛かっている状態のアニメーション
- #define METEOR_RAIN_TURN_LOOP 7
- void setup()
- {
- FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- }
- // *** REPLACE FROM HERE ***
- void loop() {
- for(int i=0;i<TWINKLE_LOOP;i++){//音楽がかかってないときの演出
- Twinkle(0xea, 0x91, 0xc98, 20, 500, false); //1ループごとに約11秒
- //なのでTWINKLE_LOOPが3なら33秒間この演出をする。
- //音楽のタイミングやクールタイムがよくわからないけど
- //ここをいじれば調整できる
- //ただし、第五引数のディレイtimeを変えてしまうと
- //1ループ11秒ではなくなってしまうので注意
- //場合によっては色を少し変えてみても
- //とりあえずピンク一色
- }
- for(int i=0;i<METEOR_RAIN_LOOP;i++){//音楽が掛かっているときの演出
- meteorRain(0x00,0xcc,0xff,10, 64, true, 25);//一回約6秒 30ループするなら180秒
- //少し変更を加えて上から下に振ってくるようにしている
- }
- for(int i=0;i<METEOR_RAIN_TURN_LOOP;i++){//音楽が掛かっているときの演出
- meteorRain_turn(0x00,0xcc,0xff,10, 64, true, 25);//こっちはしたから上へ湧き上がるような形
- // ---> here we call the effect function <---//0x33,0xff,0x00
- }
- }
- void showStrip() {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- strip.show();
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- FastLED.show();
- #endif
- }
- void setPixel(int Pixel, byte red, byte green, byte blue) {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- strip.setPixelColor(Pixel, strip.Color(red, green, blue));
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- leds[Pixel].r = red;
- leds[Pixel].g = green;
- leds[Pixel].b = blue;
- #endif
- }
- void setAll(byte red, byte green, byte blue) {
- for(int i = 0; i < NUM_LEDS; i++ ) {
- setPixel(i, red, green, blue);
- }
- showStrip();
- }
- void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
- setAll(0,0,0);
- for (int i=0; i<Count; i++) {
- setPixel(random(NUM_LEDS),red,green,blue);
- showStrip();
- delay(50);
- setPixel(random(NUM_LEDS),51,255,0);
- showStrip();
- delay(SpeedDelay);
- if(OnlyOne) {
- setAll(0,0,0);
- }
- }
- delay(SpeedDelay);
- }
- void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
- int Pixel = random(NUM_LEDS);
- setPixel(Pixel,red,green,blue);
- showStrip();
- delay(SpeedDelay);
- setPixel(Pixel,0,0,0);
- }
- void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
- setAll(0,0,0);
- for(int i = NUM_LEDS; i > 0-NUM_LEDS; i--) {
- // fade brightness all LEDs one step
- for(int j=NUM_LEDS; j>0; j--) {
- if( (!meteorRandomDecay) || (random(10)>5) ) {
- fadeToBlack(j, meteorTrailDecay );
- }
- }
- // draw meteor
- for(int j = meteorSize; j > 0; j--) {
- if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
- setPixel(i-j, red, green, blue);
- }
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- void meteorRain_turn(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
- setAll(0,0,0);
- for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
- // fade brightness all LEDs one step
- for(int j=0; j<NUM_LEDS; j++) {
- if( (!meteorRandomDecay) || (random(10)>5) ) {
- fadeToBlack(j, meteorTrailDecay );
- }
- }
- // draw meteor
- for(int j = 0; j < meteorSize; j++) {
- if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
- setPixel(i-j, red, green, blue);
- }
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- void fadeToBlack(int ledNo, byte fadeValue) {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- uint32_t oldColor;
- uint8_t r, g, b;
- int value;
- oldColor = strip.getPixelColor(ledNo);
- r = (oldColor & 0x00ff0000UL) >> 16;
- g = (oldColor & 0x0000ff00UL) >> 8;
- b = (oldColor & 0x000000ffUL);
- r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
- g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
- b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
- strip.setPixelColor(ledNo, r,g,b);
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- leds[ledNo].fadeToBlackBy( fadeValue );
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement