3000浏览
楼主: 驴友花雕

[MP动手做] 【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2022-7-20 20:40:39

  【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
  实验程序四:MegunoLink音乐反应式LED灯带
  模块接线:WS2812B接D9
  MAX9814   ESP32_C3
  VCC          5V
  GND         GND
  OUT       D4(ADC4)

  1. /*
  2.   【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
  3.   实验程序四:MegunoLink音乐反应式LED灯带
  4.   模块接线:WS2812B接D9
  5.   MAX9814   ESP32_C3
  6.   VCC          5V
  7.   GND         GND
  8.   OUT       D4(ADC4)
  9. */
  10. #include<FastLED.h>
  11. #include<MegunoLink.h>
  12. #include<Filter.h>
  13. // define necessary parameters
  14. #define N_PIXELS  24
  15. #define MIC_PIN   4
  16. #define LED_PIN   9
  17. // the following parameters can be tweaked according to your audio levels
  18. #define NOISE 150
  19. #define TOP   (N_PIXELS+2) // allow the max level to be slightly off scale
  20. #define LED_TYPE  WS2811
  21. #define BRIGHTNESS  18     // a little dim for recording purposes
  22. #define COLOR_ORDER GRB
  23. // declare the LED array
  24. CRGB leds[N_PIXELS];
  25. // define the variables needed for the audio levels
  26. int lvl = 0, minLvl = 0, maxLvl = 100; // tweak the min and max as needed
  27. // instantiate the filter class for smoothing the raw audio signal
  28. ExponentialFilter<long> ADCFilter(5,0);
  29. void setup() {
  30.   // put your setup code here, to run once:
  31.   Serial.begin(115200);
  32.   // initialize the LED object
  33.   FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,N_PIXELS).setCorrection(TypicalLEDStrip);
  34.   FastLED.setBrightness(BRIGHTNESS);
  35. }
  36. void loop() {
  37.   // put your main code here, to run repeatedly:
  38.   // read the audio signal and filter it
  39.   int n, height;
  40.   n = analogRead(MIC_PIN);
  41.   // remove the MX9614 bias of 1.25VDC
  42.   n = abs(1023 - n);
  43.   // hard limit noise/hum
  44.   n = (n <= NOISE) ? 0 : abs(n - NOISE);
  45.   // apply the exponential filter to smooth the raw signal
  46.   ADCFilter.Filter(n);
  47.   lvl = ADCFilter.Current();
  48. //  // plot the raw versus filtered signals
  49. //  Serial.print(n);
  50. //  Serial.print(" ");
  51. //  Serial.println(lvl);
  52.   // calculate the number of pixels as a percentage of the range
  53.   // TO-DO: can be done dynamically by using a running average of min/max audio levels
  54.   height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
  55.   if(height < 0L) height = 0;
  56.   else if(height > TOP) height = TOP;
  57.   // turn the LEDs corresponding to the level on/off
  58.   for(uint8_t i = 0; i < N_PIXELS; i++) {
  59.     // turn off LEDs above the current level
  60.     if(i >= height) leds[i] = CRGB(0,0,0);
  61.     // otherwise, turn them on!
  62.     else leds[i] = Wheel( map( i, 0, N_PIXELS-1, 30, 150 ) );
  63.   }
  64.   FastLED.show();
  65. }
  66. CRGB Wheel(byte WheelPos) {
  67.   // return a color value based on an input value between 0 and 255
  68.   if(WheelPos < 85)
  69.     return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
  70.   else if(WheelPos < 170) {
  71.     WheelPos -= 85;
  72.     return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
  73.   } else {
  74.     WheelPos -= 170;
  75.     return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
  76.   }
  77. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-7-20 21:02:26

实验场景图  动态图

【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-7-21 09:14:20

实验的视频记录(21秒)
https://v.youku.com/v_show/id_XNTg4NzI0MzU0NA==.html?spm=a2hcb.playlsit.page.1



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-7-21 09:28:53

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

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



回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail