9456浏览
楼主: 驴友花雕

[项目] 【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2022-9-3 18:39:22

多次失败,差点就放弃了,多方折腾后来勉强点亮......

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-3 18:55:49

  【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  项目程序之二:NeoPixel Ring 绿色柱灯

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  3.   项目程序之二:NeoPixel Ring 绿色柱灯
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #ifdef __AVR__
  7. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  8. #endif
  9. // Which pin on the Arduino is connected to the NeoPixels?
  10. #define PIN        6 // On Trinket or Gemma, suggest changing this to 1
  11. // How many NeoPixels are attached to the Arduino?
  12. #define NUMPIXELS 60 // Popular NeoPixel ring size
  13. // When setting up the NeoPixel library, we tell it how many pixels,
  14. // and which pin to use to send signals. Note that for older NeoPixel
  15. // strips you might need to change the third parameter -- see the
  16. // strandtest example for more information on possible values.
  17. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  18. #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
  19. void setup() {
  20.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  21.   // Any other board, you can remove this part (but no harm leaving it):
  22. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  23.   clock_prescale_set(clock_div_1);
  24. #endif
  25.   // END of Trinket-specific code.
  26.   pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  27. }
  28. void loop() {
  29.   pixels.clear(); // Set all pixel colors to 'off'
  30.   // The first NeoPixel in a strand is #0, second is 1, all the way up
  31.   // to the count of pixels minus one.
  32.   for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
  33.     // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  34.     // Here we're using a moderately bright green color:
  35.     pixels.setPixelColor(i, pixels.Color(0, 250, 0));
  36.     pixels.show();   // Send the updated pixel colors to the hardware.
  37.     delay(100); // Pause before next pass through loop
  38.   }
  39. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-3 19:15:19

本帖最后由 驴友花雕 于 2022-9-3 19:29 编辑

实验的视频记录(1分02秒)

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1







回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-3 19:25:31

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-3 19:35:12

  【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  项目程序之三:NeoPixel 测试程序

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  3.   项目程序之三:NeoPixel 测试程序
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #ifdef __AVR__
  7. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  8. #endif
  9. // Which pin on the Arduino is connected to the NeoPixels?
  10. // On a Trinket or Gemma we suggest changing this to 1:
  11. #define LED_PIN    6
  12. // How many NeoPixels are attached to the Arduino?
  13. #define LED_COUNT 60
  14. // Declare our NeoPixel strip object:
  15. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  16. // Argument 1 = Number of pixels in NeoPixel strip
  17. // Argument 2 = Arduino pin number (most are valid)
  18. // Argument 3 = Pixel type flags, add together as needed:
  19. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  20. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  21. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  22. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  23. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  24. // setup() function -- runs once at startup --------------------------------
  25. void setup() {
  26.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  27.   // Any other board, you can remove this part (but no harm leaving it):
  28. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  29.   clock_prescale_set(clock_div_1);
  30. #endif
  31.   // END of Trinket-specific code.
  32.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  33.   strip.show();            // Turn OFF all pixels ASAP
  34.   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  35. }
  36. // loop() function -- runs repeatedly as long as board is on ---------------
  37. void loop() {
  38.   // Fill along the length of the strip in various colors...
  39.   colorWipe(strip.Color(255,   0,   0), 50); // Red
  40.   colorWipe(strip.Color(  0, 255,   0), 50); // Green
  41.   colorWipe(strip.Color(  0,   0, 255), 50); // Blue
  42.   // Do a theater marquee effect in various colors...
  43.   theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  44.   theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  45.   theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
  46.   rainbow(10);             // Flowing rainbow cycle along the whole strip
  47.   theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
  48. }
  49. // Some functions of our own for creating animated effects -----------------
  50. // Fill strip pixels one after another with a color. Strip is NOT cleared
  51. // first; anything there will be covered pixel by pixel. Pass in color
  52. // (as a single 'packed' 32-bit value, which you can get by calling
  53. // strip.Color(red, green, blue) as shown in the loop() function above),
  54. // and a delay time (in milliseconds) between pixels.
  55. void colorWipe(uint32_t color, int wait) {
  56.   for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  57.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  58.     strip.show();                          //  Update strip to match
  59.     delay(wait);                           //  Pause for a moment
  60.   }
  61. }
  62. // Theater-marquee-style chasing lights. Pass in a color (32-bit value,
  63. // a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
  64. // between frames.
  65. void theaterChase(uint32_t color, int wait) {
  66.   for (int a = 0; a < 10; a++) { // Repeat 10 times...
  67.     for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
  68.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  69.       // 'c' counts up from 'b' to end of strip in steps of 3...
  70.       for (int c = b; c < strip.numPixels(); c += 3) {
  71.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  72.       }
  73.       strip.show(); // Update strip with new contents
  74.       delay(wait);  // Pause for a moment
  75.     }
  76.   }
  77. }
  78. // Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
  79. void rainbow(int wait) {
  80.   // Hue of first pixel runs 5 complete loops through the color wheel.
  81.   // Color wheel has a range of 65536 but it's OK if we roll over, so
  82.   // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  83.   // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  84.   for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
  85.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  86.       // Offset pixel hue by an amount to make one full revolution of the
  87.       // color wheel (range of 65536) along the length of the strip
  88.       // (strip.numPixels() steps):
  89.       int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  90.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  91.       // optionally add saturation and value (brightness) (each 0 to 255).
  92.       // Here we're using just the single-argument hue variant. The result
  93.       // is passed through strip.gamma32() to provide 'truer' colors
  94.       // before assigning to each pixel:
  95.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  96.     }
  97.     strip.show(); // Update strip with new contents
  98.     delay(wait);  // Pause for a moment
  99.   }
  100. }
  101. // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
  102. void theaterChaseRainbow(int wait) {
  103.   int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  104.   for (int a = 0; a < 30; a++) { // Repeat 30 times...
  105.     for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
  106.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  107.       // 'c' counts up from 'b' to end of strip in increments of 3...
  108.       for (int c = b; c < strip.numPixels(); c += 3) {
  109.         // hue of pixel 'c' is offset by an amount to make one full
  110.         // revolution of the color wheel (range 65536) along the length
  111.         // of the strip (strip.numPixels() steps):
  112.         int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
  113.         uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
  114.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  115.       }
  116.       strip.show();                // Update strip with new contents
  117.       delay(wait);                 // Pause for a moment
  118.       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  119.     }
  120.   }
  121. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-4 19:01:58

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-4 19:22:48

实验的视频记录(1分29秒)

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 06:28:56

  【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  项目程序之四:音乐反应LED无限魔方
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  3.   项目程序之四:音乐反应LED无限魔方
  4.   模块接线:WS2812B接D6
  5.   MAX4466      UNO
  6.   VCC          5V
  7.   GND         GND
  8.   OUT          A0
  9. */
  10. #include<FastLED.h>
  11. #define LED_PIN 6
  12. #define NUM_LEDS 60
  13. CRGB leds[NUM_LEDS];
  14. uint8_t hue = 0;
  15. int soundsensor = A0;
  16. void setup() {
  17.   delay(2000);
  18.   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  19.   FastLED.setBrightness(155);
  20.   pinMode(soundsensor, INPUT);
  21. }
  22. void loop() {
  23.   int sensval = digitalRead(soundsensor);
  24.   if (sensval == 1) {
  25.     leds[0] = CRGB :: Red;
  26.     fill_solid(leds, NUM_LEDS, CRGB :: Blue);
  27.     rainbow_moving();
  28.     FastLED.show();
  29.     delay(10);
  30.   }
  31.   else {
  32.     leds[0] = CRGB :: Black;
  33.     fill_solid(leds, NUM_LEDS, CRGB :: Black);
  34.     FastLED.show();
  35.     delay(10);
  36.   }
  37. }
  38. void rainbow_moving() {
  39.   for (int i = 0; i < NUM_LEDS; i++) {
  40.     leds[i] = CHSV(hue + (i * 10), 255, 255);
  41.   }
  42.   EVERY_N_MILLISECONDS(10) {
  43.     hue++;
  44.   }
  45. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 06:59:12

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 07:06:28

实验的视频记录(2分51秒)

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 11:25:01

  【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  项目程序之五:多彩MegunoLink音乐节拍灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  3.   项目程序之五:多彩MegunoLink音乐节拍灯
  4.   模块接线:WS2812B接D6
  5.   MAX4466      UNO
  6.   VCC          5V
  7.   GND         GND
  8.   OUT          A0
  9. */
  10. #include<FastLED.h>
  11. #include<MegunoLink.h>
  12. #include<Filter.h>
  13. #define N_PIXELS  60
  14. #define MIC_PIN   A0
  15. #define LED_PIN   6
  16. #define NOISE 10
  17. #define TOP   (N_PIXELS+2)
  18. #define LED_TYPE  WS2811
  19. #define BRIGHTNESS  10
  20. #define COLOR_ORDER GRB
  21. CRGB leds[N_PIXELS];
  22. int lvl = 0, minLvl = 0, maxLvl = 10;
  23. ExponentialFilter<long> ADCFilter(5, 0);
  24. void setup() {
  25.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, N_PIXELS).setCorrection(TypicalLEDStrip);
  26.   FastLED.setBrightness(BRIGHTNESS);
  27. }
  28. void loop() {
  29.   int n, height;
  30.   n = analogRead(MIC_PIN);
  31.   n = abs(1023 - n);
  32.   n = (n <= NOISE) ? 0 : abs(n - NOISE);
  33.   ADCFilter.Filter(n);
  34.   lvl = ADCFilter.Current();
  35.   //  Serial.print(n);
  36.   //  Serial.print(" ");
  37.   //  Serial.println(lvl);
  38.   height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
  39.   if (height < 0L) height = 0;
  40.   else if (height > TOP) height = TOP;
  41.   for (uint8_t i = 0; i < N_PIXELS; i++) {
  42.     if (i >= height) leds[i] = CRGB(0, 0, 0);
  43.     else leds[i] = Wheel( map( i, 0, N_PIXELS - 1, 30, 150 ) );
  44.   }
  45.   FastLED.show();
  46. }
  47. CRGB Wheel(byte WheelPos) {
  48.   if (WheelPos < 85)
  49.     return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
  50.   else if (WheelPos < 170) {
  51.     WheelPos -= 85;
  52.     return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
  53.   } else {
  54.     WheelPos -= 170;
  55.     return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
  56.   }
  57. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 16:21:30

实验的视频记录(4分50秒)

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1





回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-5 16:27:55

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 13:08:19

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 17:45:47

参考LED序列

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 17:53:30

  【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  项目程序之六:一个用 FastLED 编程的LED无限魔方体


  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(22)--LED无限魔方
  3.   项目程序之六:一个用 FastLED 编程的LED无限魔方体
  4. */
  5. #include <FastLED.h>
  6. #define LED_PIN               6
  7. #define LEDS_PER_SEGMENT      5
  8. #define SEGMENTS              12
  9. #define BRIGHTNESS            200
  10. #define NUM_LEDS              LEDS_PER_SEGMENT * SEGMENTS
  11. #define NUM_LEDS_WITH_SAFETY  NUM_LEDS + 1
  12. CRGB source1[NUM_LEDS_WITH_SAFETY];
  13. CRGB source2[NUM_LEDS_WITH_SAFETY];
  14. CRGB output[NUM_LEDS_WITH_SAFETY];
  15. uint8_t blendAmount = 0;
  16. uint8_t patternCounter = 0;
  17. uint8_t source1Pattern = 0;
  18. uint8_t source2Pattern = 1;
  19. bool useSource1 = false;
  20. void setup() {
  21.   FastLED.addLeds<WS2812B, LED_PIN, GRB>(output, NUM_LEDS_WITH_SAFETY);
  22.   FastLED.setBrightness(BRIGHTNESS);
  23.   Serial.begin(57600);
  24. }
  25. void loop() {
  26.   EVERY_N_MILLISECONDS(10) {
  27.     blend(source1, source2, output, NUM_LEDS, blendAmount);   //在两个源之间混合
  28.     if (useSource1) {
  29.       if (blendAmount < 255) blendAmount++;                   //混合“向上”到源 2
  30.     } else {
  31.       if (blendAmount > 0) blendAmount--;                     //将“向下”混合到源 1
  32.     }
  33.   }
  34.   EVERY_N_SECONDS(8) {
  35.     nextPattern();
  36.   }
  37.   runPattern(source1Pattern, source1);                  //同时运行两种模式
  38.   runPattern(source2Pattern, source2);
  39.   
  40.   FastLED.show();
  41. }
  42. void nextPattern() {
  43.   patternCounter = (patternCounter + 1) % 5;
  44.   if (useSource1) source1Pattern = patternCounter;
  45.   else source2Pattern = patternCounter;
  46.   useSource1 = !useSource1;
  47. }
  48. void runPattern(uint8_t pattern, CRGB *LEDarray) {
  49.   switch (pattern) {
  50.     case 0:
  51.       rainbowComet(LEDarray);//彩虹彗星
  52.       break;
  53.     case 1:
  54.       prettyNoise(LEDarray);//漂亮噪声
  55.       break;
  56.     case 2:
  57.       randomStar(LEDarray);//随机星
  58.       break;
  59.     case 3:
  60.       fillRainbow(LEDarray);//填充彩虹
  61.       break;
  62.     case 4:
  63.       pixels(LEDarray);// 像素
  64.       break;
  65.   }
  66. }
  67. uint8_t xyz(uint8_t x, uint8_t y, uint8_t z) {
  68. /*边缘的坐标从 0 到 5。每条边缘只有 5 个“真实”像素,
  69.    * 所以只有 1 - 5 个 LED。缺少顶点(角)。
  70.    * 如果请求这些顶点之一,则返回一个不显示的安全像素。
  71.    * 我们对立方体内部的坐标也做同样的事情,即不在边缘上。
  72.    */
  73.   uint8_t lps = LEDS_PER_SEGMENT;
  74.   uint8_t safePx = NUM_LEDS;
  75.   if ((x == 0 || x == lps + 1) && (y == 0 || y == lps + 1) && (z == 0 || z == lps + 1)) return safePx;
  76.   // z 方向边缘
  77.   if (x == 0        && y == 0)        return (8 * lps)  - z;      // Seg 7
  78.   if (x == 0        && y == lps + 1)  return (12 * lps) - z;      // Seg 11
  79.   if (x == lps + 1  && y == 0)        return (3 * lps)  + z - 1;  // Seg 3
  80.   if (x == lps + 1  && y == lps + 1)  return (9 * lps)  + z - 1;  // Seg 9
  81.   // y 方向边
  82.   if (x == 0        && z == 0)        return y - 1;               // Seg 0
  83.   if (x == 0        && z == lps + 1)  return (7 * lps)  - y;      // Seg 6
  84.   if (x == lps + 1  && z == 0)        return (3 * lps)  - y;      // Seg 2
  85.   if (x == lps + 1  && z == lps + 1)  return (4 * lps)  + y - 1;  // Seg 4
  86.   // x 方向边
  87.   if (y == 0        && z == 0)        return (8 * lps)  + x - 1;  // Seg 8
  88.   if (y == 0        && z == lps + 1)  return (11 * lps) - x;      // Seg 10
  89.   if (y == lps + 1  && z == 0)        return lps        + x - 1;  // Seg 1
  90.   if (y == lps + 1  && z == lps + 1)  return (6 * lps)  - x;      // Seg 5
  91.   //如果以上都不是,我们的坐标无效
  92.   return safePx;
  93. }
  94. //------------ Patterns below ------------//
  95. void pixels(CRGB *LEDarray) {
  96.   static uint8_t pos = 0;
  97.   static uint8_t a = 0;
  98.   static uint8_t b = 0;
  99.   //填充所有像素并将它们混合在一起
  100.   for (int c = 0; c <= LEDS_PER_SEGMENT + 1; c++) {
  101.     LEDarray[xyz(a,b,c)] = blend(LEDarray[xyz(a,b,c)], CRGB::Orange, 128);
  102.     LEDarray[xyz(a,c,b)] = blend(LEDarray[xyz(a,c,b)], CRGB::Magenta, 128);
  103.     LEDarray[xyz(c,a,b)] = blend(LEDarray[xyz(c,a,b)], CRGB::Blue, 128);
  104.   }
  105.   EVERY_N_MILLISECONDS(33) {   
  106.     //围绕正方形移动的坐标
  107.     if(pos < 15) a++;
  108.     else if (pos <= (LEDS_PER_SEGMENT * 2) + 1) b++;
  109.     else if (pos <= (LEDS_PER_SEGMENT * 3) + 2) a--;
  110.     else b--;
  111.      //再次开始我们到达正方形的尽头
  112.     pos = (pos + 1) % ((LEDS_PER_SEGMENT + 1) * 4);
  113.   }
  114.   fadeToBlackBy(LEDarray, NUM_LEDS, 10);
  115.   
  116. }
  117. void fillRainbow(CRGB *LEDarray) {
  118.   static uint8_t pos = 0;
  119.   
  120.   uint8_t noise = inoise8(millis()/5);
  121.   fill_rainbow(LEDarray, LEDS_PER_SEGMENT, noise, 10);
  122.   //复制到其他段
  123.   for (int i = 0; i < SEGMENTS; i++) {
  124.     memmove8(&LEDarray[LEDS_PER_SEGMENT * i], &LEDarray[0], LEDS_PER_SEGMENT * sizeof(CRGB));
  125.   }
  126.    //垂直柱子上下移动的白点
  127.   LEDarray[xyz(0, 0, LEDS_PER_SEGMENT - pos)] = CRGB::White;
  128.   LEDarray[xyz(0, LEDS_PER_SEGMENT + 1, pos)] = CRGB::White;
  129.   LEDarray[xyz(LEDS_PER_SEGMENT + 1, LEDS_PER_SEGMENT + 1, LEDS_PER_SEGMENT - pos)] = CRGB::White;
  130.   LEDarray[xyz(LEDS_PER_SEGMENT + 1, 0, pos)] = CRGB::White;
  131.   EVERY_N_MILLISECONDS(20) {
  132.     pos = (pos + 1) % LEDS_PER_SEGMENT;
  133.   }
  134. }
  135. void rainbowComet(CRGB *LEDarray) {
  136.   static uint8_t easeOutVal = 0;
  137.   static uint8_t easeInVal  = 0;
  138.   //使图案出现在两个段上
  139.   uint8_t ledsPerSegment = LEDS_PER_SEGMENT * 2;
  140.   uint8_t segments = SEGMENTS / 2;
  141.   easeOutVal = ease8InOutQuad(easeInVal);
  142.   easeInVal++;
  143.   uint8_t pos = lerp8by8(0, ledsPerSegment, easeOutVal);
  144.   uint8_t hue =  map(pos, 0, ledsPerSegment, 0, 230);
  145.   
  146.   LEDarray[pos] = CHSV(hue, 255, 255);
  147.   fadeToBlackBy(LEDarray, ledsPerSegment, 20);
  148.   //复制到其他段
  149.   for (int i = 0; i < segments; i++) {
  150.     memmove8(&LEDarray[ledsPerSegment * i], &LEDarray[0], ledsPerSegment * sizeof(CRGB));
  151.   }
  152. }
  153. void randomStar(CRGB *LEDarray) {
  154.   EVERY_N_MILLISECONDS(75) {
  155.     LEDarray[random16(0, NUM_LEDS)] = CRGB::LightGrey;
  156.   }
  157.   for (int i = 0; i < NUM_LEDS; i++) {
  158.    
  159.     // 亮度
  160.     uint8_t bNoise = inoise8(i * 100, millis());
  161.     bNoise = constrain(bNoise, 50, 200);
  162.     bNoise = map(bNoise, 50, 200, 20, 80);
  163.     // 色调
  164.     uint8_t hNoise = inoise8(i * 20, millis() / 5);
  165.     hNoise = constrain(hNoise, 50, 200);
  166.     hNoise = map(hNoise, 50, 200, 160, 192);
  167.    
  168.     if (LEDarray[i].g == 0) {
  169.       LEDarray[i] = CHSV(hNoise, 255, bNoise);
  170.     }
  171.   }
  172.   
  173.   fadeToBlackBy(LEDarray, NUM_LEDS, 5);//淡入黑色(LED 阵列,NUM LEDS,5 个)
  174. }
  175. void prettyNoise(CRGB *LEDarray) {
  176.   fill_noise16 (LEDarray, NUM_LEDS, 1, 0, 100, 1, 1, 50, millis() / 3, 5);
  177. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 19:24:36

实验的视频记录(4分37秒)

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 19:26:17

实验场景图  

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-1 19:32:58

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-1 19:35:08

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-5 10:14:33

【花雕动手做】看见声音,基于Arduino系列音乐可视器(1)---LED节奏灯
https://mc.dfrobot.com.cn/thread-311167-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(2)---OLED频谱灯
https://mc.dfrobot.com.cn/thread-311174-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(3)---RGB律动灯
https://mc.dfrobot.com.cn/thread-311183-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(4)---WS2812条灯
https://mc.dfrobot.com.cn/thread-311190-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(5)---WS2812柱跳灯
https://mc.dfrobot.com.cn/thread-311192-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(6)---点阵频谱灯
https://mc.dfrobot.com.cn/thread-311201-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(7)---大方格频谱灯
https://mc.dfrobot.com.cn/thread-311364-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(8)---四位32段点阵屏
https://mc.dfrobot.com.cn/thread-311490-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(9)---X Music Spectrum
https://mc.dfrobot.com.cn/thread-311627-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(10)---WS2812硬板屏
https://mc.dfrobot.com.cn/thread-311641-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(11)---WS2812幻彩灯带
https://mc.dfrobot.com.cn/thread-313648-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(12)---米管快速节奏灯
https://mc.dfrobot.com.cn/thread-313708-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(13)---有机棒立柱灯
https://mc.dfrobot.com.cn/thread-313723-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(14)---水杯水瓶灯
https://mc.dfrobot.com.cn/thread-313803-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(15)--横排LED方管灯
https://mc.dfrobot.com.cn/thread-313811-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(16)--热干胶棒棒灯
https://mc.dfrobot.com.cn/thread-313844-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(17)--光导纤维灯
https://mc.dfrobot.com.cn/thread-313867-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(18)--LED平面板灯
https://mc.dfrobot.com.cn/thread-313951-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(19)--通体光纤灯
https://mc.dfrobot.com.cn/thread-313962-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(20)--首饰盒镜子灯
https://mc.dfrobot.com.cn/thread-313969-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(21)--CD 光盘灯
https://mc.dfrobot.com.cn/thread-313984-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)--LED无限魔方
https://mc.dfrobot.com.cn/thread-313994-1-1.html
【花雕动手做】有趣好玩的音乐可视化(23)--3合1闪点光纤
https://mc.dfrobot.com.cn/thread-314168-1-1.html
【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯
https://mc.dfrobot.com.cn/thread-314180-1-1.html
【花雕动手做】有趣好玩音乐可视化(25)--水龙卷旋涡灯
https://mc.dfrobot.com.cn/thread-314231-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(26)--LED 超立方体
https://mc.dfrobot.com.cn/thread-314244-1-1.html
【花雕动手做】有趣好玩的音乐可视化(27)--磁搅LED水旋灯
https://mc.dfrobot.com.cn/thread-314273-1-1.html


回复

使用道具 举报

12
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail