Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. #include <FastLED.h>
  2. #define NUM_LEDS 100
  3. CRGB leds[NUM_LEDS];
  4. #define PIN 14
  5. #define TWINKLE_LOOP 2 //ここを変えるとTWINKLE_LOOP*約11秒の演出に 想定では音楽が掛かていない状態のアニメーション
  6. #define METEOR_RAIN_LOOP 7//ここを変えると*6秒の演出に 想定では音楽が掛かっている状態のアニメーション
  7. #define METEOR_RAIN_TURN_LOOP 7
  8. void setup()
  9. {
  10. FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  11.  
  12. }
  13.  
  14. // *** REPLACE FROM HERE ***
  15. void loop() {
  16.  
  17.  
  18. for(int i=0;i<TWINKLE_LOOP;i++){//音楽がかかってないときの演出
  19. Twinkle(0xea, 0x91, 0xc98, 20, 500, false); //1ループごとに約11秒
  20. //なのでTWINKLE_LOOPが3なら33秒間この演出をする。
  21. //音楽のタイミングやクールタイムがよくわからないけど
  22. //ここをいじれば調整できる
  23. //ただし、第五引数のディレイtimeを変えてしまうと
  24. //1ループ11秒ではなくなってしまうので注意
  25. //場合によっては色を少し変えてみても
  26. //とりあえずピンク一色
  27. }
  28. for(int i=0;i<METEOR_RAIN_LOOP;i++){//音楽が掛かっているときの演出
  29.  
  30. meteorRain(0x00,0xcc,0xff,10, 64, true, 25);//一回約6秒 30ループするなら180秒
  31. //少し変更を加えて上から下に振ってくるようにしている
  32. }
  33.  
  34. for(int i=0;i<METEOR_RAIN_TURN_LOOP;i++){//音楽が掛かっているときの演出
  35. meteorRain_turn(0x00,0xcc,0xff,10, 64, true, 25);//こっちはしたから上へ湧き上がるような形
  36. // ---> here we call the effect function <---//0x33,0xff,0x00
  37. }
  38.  
  39.  
  40. }
  41.  
  42.  
  43.  
  44. void showStrip() {
  45. #ifdef ADAFRUIT_NEOPIXEL_H
  46. // NeoPixel
  47. strip.show();
  48. #endif
  49. #ifndef ADAFRUIT_NEOPIXEL_H
  50. // FastLED
  51. FastLED.show();
  52. #endif
  53. }
  54.  
  55. void setPixel(int Pixel, byte red, byte green, byte blue) {
  56. #ifdef ADAFRUIT_NEOPIXEL_H
  57. // NeoPixel
  58. strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  59. #endif
  60. #ifndef ADAFRUIT_NEOPIXEL_H
  61. // FastLED
  62. leds[Pixel].r = red;
  63. leds[Pixel].g = green;
  64. leds[Pixel].b = blue;
  65. #endif
  66. }
  67.  
  68. void setAll(byte red, byte green, byte blue) {
  69. for(int i = 0; i < NUM_LEDS; i++ ) {
  70. setPixel(i, red, green, blue);
  71. }
  72. showStrip();
  73. }
  74.  
  75. void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {
  76. setAll(0,0,0);
  77.  
  78. for (int i=0; i<Count; i++) {
  79. setPixel(random(NUM_LEDS),red,green,blue);
  80. showStrip();
  81. delay(50);
  82. setPixel(random(NUM_LEDS),51,255,0);
  83. showStrip();
  84. delay(SpeedDelay);
  85. if(OnlyOne) {
  86. setAll(0,0,0);
  87. }
  88. }
  89.  
  90. delay(SpeedDelay);
  91. }
  92.  
  93. void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  94. int Pixel = random(NUM_LEDS);
  95. setPixel(Pixel,red,green,blue);
  96. showStrip();
  97. delay(SpeedDelay);
  98. setPixel(Pixel,0,0,0);
  99. }
  100.  
  101. void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
  102. setAll(0,0,0);
  103.  
  104. for(int i = NUM_LEDS; i > 0-NUM_LEDS; i--) {
  105.  
  106.  
  107. // fade brightness all LEDs one step
  108. for(int j=NUM_LEDS; j>0; j--) {
  109. if( (!meteorRandomDecay) || (random(10)>5) ) {
  110. fadeToBlack(j, meteorTrailDecay );
  111. }
  112. }
  113.  
  114. // draw meteor
  115. for(int j = meteorSize; j > 0; j--) {
  116. if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
  117. setPixel(i-j, red, green, blue);
  118. }
  119. }
  120.  
  121. showStrip();
  122. delay(SpeedDelay);
  123. }
  124. }
  125.  
  126.  
  127. void meteorRain_turn(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
  128. setAll(0,0,0);
  129.  
  130. for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
  131.  
  132.  
  133. // fade brightness all LEDs one step
  134. for(int j=0; j<NUM_LEDS; j++) {
  135. if( (!meteorRandomDecay) || (random(10)>5) ) {
  136. fadeToBlack(j, meteorTrailDecay );
  137. }
  138. }
  139.  
  140. // draw meteor
  141. for(int j = 0; j < meteorSize; j++) {
  142. if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
  143. setPixel(i-j, red, green, blue);
  144. }
  145. }
  146.  
  147. showStrip();
  148. delay(SpeedDelay);
  149. }
  150. }
  151.  
  152. void fadeToBlack(int ledNo, byte fadeValue) {
  153. #ifdef ADAFRUIT_NEOPIXEL_H
  154. // NeoPixel
  155. uint32_t oldColor;
  156. uint8_t r, g, b;
  157. int value;
  158.  
  159. oldColor = strip.getPixelColor(ledNo);
  160. r = (oldColor & 0x00ff0000UL) >> 16;
  161. g = (oldColor & 0x0000ff00UL) >> 8;
  162. b = (oldColor & 0x000000ffUL);
  163.  
  164. r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
  165. g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
  166. b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
  167.  
  168. strip.setPixelColor(ledNo, r,g,b);
  169. #endif
  170. #ifndef ADAFRUIT_NEOPIXEL_H
  171. // FastLED
  172. leds[ledNo].fadeToBlackBy( fadeValue );
  173. #endif
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement