5441浏览
查看: 5441|回复: 18

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

[复制链接]
偶然脑子发热心血来潮,想要做一个声音可视化的系列专题。这个专题的难度有点高,涉及面也比较广泛,相关的FFT和FHT等算法也相当复杂,不过还是打算从最简单的开始,实际动手做做试验,耐心尝试一下各种方案,逐步积累些有用的音乐频谱可视化的资料,也会争取成型一些实用好玩的音乐可视器项目。

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
项目所需材料如下:

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

驴友花雕  中级技神
 楼主|

发表于 2021-10-8 19:30:49

Arduino 系列传感器和执行器模块实验目录清单:
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
https://mc.dfrobot.com.cn/thread-280845-1-1.html
连杆形式的腿机构十一种:盘点机器人行走背后的机械原理
https://mc.dfrobot.com.cn/thread-308097-1-1.html
【花雕动手做】超低成本,尝试五十元的麦克纳姆轮小车!
https://mc.dfrobot.com.cn/thread-307863-1-1.html
【花雕动手做】超迷你哦,用徽商香烟盒做个智能小车!
https://mc.dfrobot.com.cn/thread-307907-1-1.html
【花雕动手做】太搞笑啦,一支胶管制成二只蠕动机器人
https://mc.dfrobot.com.cn/thread-308046-1-1.html
【花雕动手做】快餐盒盖,极低成本搭建机器人实验平台
https://mc.dfrobot.com.cn/thread-308063-1-1.html
【花雕动手做】特别苗条,使用微波传感器控制的纤细小车
https://mc.dfrobot.com.cn/thread-308866-1-1.html
【花雕动手做】脑洞大开、五花八门的简易机器人66种
https://mc.dfrobot.com.cn/thread-307900-1-1.html
【花雕动手做】看见声音,基于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

实验一百五十八:QMC5883L电子指南针罗盘模块 三轴磁场传感器GY-271
https://mc.dfrobot.com.cn/thread-308195-1-1.html
实验一百六十三:BMI160 6轴惯性运动传感器 16位3轴加速度+超低功耗3轴陀螺仪  I2C/SPI 14LGA
https://mc.dfrobot.com.cn/thread-310371-1-1.html
实验一百六十五:2.4 英寸 TFT LCD 触摸屏模块 XPT2046 PCB ILI9341 240x320 像素 8 位 SPI 串口显示器 300mA
https://mc.dfrobot.com.cn/thread-309803-1-1.html
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
https://mc.dfrobot.com.cn/thread-309845-1-1.html
实验一百七十九:0.66英寸OLED显示模块 液晶屏模块IIC/I2C接口 64*48像素 SSD1306驱动芯片
https://mc.dfrobot.com.cn/thread-311179-1-1.html
实验一百八十一:1.3寸OLED液晶屏  I2C IIC通信 4针模块 1106/1306驱动 128*64像素
https://mc.dfrobot.com.cn/thread-311123-1-1.html
实验一百八十三:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议
https://mc.dfrobot.com.cn/thread-310273-1-1.html
实验一百八十五:MAX4466声音传感器 驻极体话筒放大器 麦克风可调功放模块 microphone
https://mc.dfrobot.com.cn/thread-310193-1-1.html
实验一百八十九:TDA1308 硅麦克风 数字咪头放大模块 拾音器放大板 楼氏SUNLEPHANT
https://mc.dfrobot.com.cn/thread-310246-1-1.html
实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
https://mc.dfrobot.com.cn/thread-310209-1-1.html
实验二百:RCWL-0515微波雷达感应开关 人体感应 智能感应探测传感器 12-15米远距离2.7G微波检测模块
https://mc.dfrobot.com.cn/thread-310313-1-1.html
实验二百零一:OPT101模拟光照传感器 TEMT6000光强度模块 单片光电二极管 YourCee
https://mc.dfrobot.com.cn/thread-311164-1-1.html
实验二百零三:Air724UG合宙 Cat14G模块 DTU物联网UART串口通信数据TCP透传 核心板组合套餐
https://mc.dfrobot.com.cn/thread-310342-1-1.html
实验二百零七:I2C红色8*8LED点阵模块ht16k33驱动1088BS树莓派物联网可扩展编程
https://mc.dfrobot.com.cn/thread-310951-1-1.html
实验二百零九:Gravity: I2C & UART BC20 NB-IoT & GNSS通信模块 NB-IoT广域低功耗无线通信 GPS/北斗精准定位
https://mc.dfrobot.com.cn/thread-310433-1-1.html

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-8 19:42:42

MAX9814是一款低成本高性能麦克风放大器,具有自动增益控制(AGC)和低噪声麦克风偏置。器件具有低噪声前端放大器、可变增益放大(VGA)、输出放大器、麦克风偏置电压发生器和AGC控制电路。
●自动增益控制(AGC)  
●3种增益设置(40dB、50dB、60dB)  
●可编程动作时间  
●可编程动作和释放时间比  
●电源电压范围2.7V~5.5V   
●低THD:0.04% (典型值)  
●低功耗关断模式  
●内置2V低噪声麦克风偏置

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 06:19:11

WS2812B
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。


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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 06:22:34

WS2812主要特点
1、智能反接保护,电源反接不会损坏IC。
2、IC控制电路与LED点光源公用一个电源。
3、控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。
4、内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。
5、内置上电复位和掉电复位电路。
6、每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。
7、串行级联接口,能通过一根信号线完成数据的接收与解码。
8、任意两点传传输距离在不超过5米时无需增加任何电路。
9、当刷新速率30帧/秒时,级联数不小于1024点。
10、数据发送速度可达800Kbps。
11、光的颜色高度一致,性价比高。


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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 06:54:08

本帖最后由 驴友花雕 于 2021-10-9 07:10 编辑

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之一:使用MAX9814的音乐反应简单柱跳灯

  实验开源代码

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  3.   项目之一:使用MAX9814的音乐反应简单柱跳灯
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #include <math.h>
  7. #define N_PIXELS  8
  8. #define MIC_PIN   A0
  9. #define LED_PIN    6
  10. #define SAMPLE_WINDOW   5
  11. #define PEAK_HANG 24
  12. #define PEAK_FALL 4
  13. #define INPUT_FLOOR 10
  14. #define INPUT_CEILING 50
  15. byte peak = 16;
  16. unsigned int sample;
  17. byte Count = 0;
  18. byte HangCount = 0;
  19. Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
  20. void setup() {
  21.   Serial.begin(9600);
  22.   analogReference(EXTERNAL);
  23.   strip.setBrightness(22);
  24.   strip.show();
  25.   strip.begin();
  26. }
  27. float fscale( float originalMin, float originalMax, float newBegin, float newEnd, float inputValue, float curve) {
  28.   float OriginalRange = 0;
  29.   float NewRange = 0;
  30.   float zeroRefCurVal = 0;
  31.   float normalizedCurVal = 0;
  32.   float rangedValue = 0;
  33.   boolean invFlag = 0;
  34.   if (curve > 10) curve = 10;
  35.   if (curve < -10) curve = -10;
  36.   curve = (curve * -.1) ;
  37.   curve = pow(10, curve);
  38.   if (inputValue < originalMin) {
  39.     inputValue = originalMin;
  40.   }
  41.   if (inputValue > originalMax) {
  42.     inputValue = originalMax;
  43.   }
  44.   OriginalRange = originalMax - originalMin;
  45.   if (newEnd > newBegin) {
  46.     NewRange = newEnd - newBegin;
  47.   }
  48.   else
  49.   {
  50.     NewRange = newBegin - newEnd;
  51.     invFlag = 1;
  52.   }
  53.   zeroRefCurVal = inputValue - originalMin;
  54.   normalizedCurVal  =  zeroRefCurVal / OriginalRange;   // normalize to 0 - 1 float
  55.   Serial.print(OriginalRange, DEC);
  56.   Serial.print("   ");
  57.   Serial.print(NewRange, DEC);
  58.   Serial.print("   ");
  59.   Serial.println(zeroRefCurVal, DEC);
  60.   Serial.println();
  61.   delay(10);
  62.   if (originalMin > originalMax ) {
  63.     return 0;
  64.   }
  65.   if (invFlag == 0) {
  66.     rangedValue =  (pow(normalizedCurVal, curve) * NewRange) + newBegin;
  67.   }
  68.   else
  69.   {
  70.     rangedValue =  newBegin - (pow(normalizedCurVal, curve) * NewRange);
  71.   }
  72.   return rangedValue;
  73. }
  74. void loop() {
  75.   unsigned long startMillis = millis();
  76.   float peakToPeak = 0;
  77.   unsigned int signalMax = 0;
  78.   unsigned int signalMin = 1023;
  79.   unsigned int c, y;
  80.   while (millis() - startMillis < SAMPLE_WINDOW)
  81.   {
  82.     sample = analogRead(MIC_PIN);
  83.     if (sample < 1024)
  84.     {
  85.       if (sample > signalMax)
  86.       {
  87.         signalMax = sample;
  88.       }
  89.       else if (sample < signalMin)
  90.       {
  91.         signalMin = sample;
  92.       }
  93.     }
  94.   }
  95.   peakToPeak = signalMax - signalMin;
  96.   for (int i = 0; i <= strip.numPixels() - 1; i++) {
  97.     strip.setPixelColor(i, Wheel(map(i, 0, strip.numPixels() - 1, 30, 150)));
  98.   }
  99.   c = fscale(INPUT_FLOOR, INPUT_CEILING, strip.numPixels(), 0, peakToPeak, 2);
  100.   if (c < peak) {
  101.     peak = c;
  102.     HangCount = 0;
  103.   }
  104.   if (c <= strip.numPixels()) {
  105.     drawLine(strip.numPixels(), strip.numPixels() - c, strip.Color(0, 0, 0));
  106.   }
  107.   y = strip.numPixels() - peak;
  108.   strip.setPixelColor(y - 1, Wheel(map(y, 0, strip.numPixels() - 1, 30, 150)));
  109.   strip.show();
  110.   if (HangCount > PEAK_HANG) {
  111.     if (++Count >= PEAK_FALL) {
  112.       peak++;
  113.       Count = 0;
  114.     }
  115.   }
  116.   else {
  117.     HangCount++;
  118.   }
  119. }
  120. void drawLine(uint8_t from, uint8_t to, uint32_t c) {
  121.   uint8_t fromTemp;
  122.   if (from > to) {
  123.     fromTemp = from;
  124.     from = to;
  125.     to = fromTemp;
  126.   }
  127.   for (int i = from; i <= to; i++) {
  128.     strip.setPixelColor(i, c);
  129.   }
  130. }
  131. uint32_t Wheel(byte WheelPos) {
  132.   if (WheelPos < 85) {
  133.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  134.   }
  135.   else if (WheelPos < 170) {
  136.     WheelPos -= 85;
  137.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  138.   }
  139.   else {
  140.     WheelPos -= 170;
  141.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  142.   }
  143. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 07:01:14

实验场景图

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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 07:09:49

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之一:使用MAX9814的音乐反应简单柱跳灯

  实验视频剪辑

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



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 07:31:13

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之一:使用MAX9814的音乐反应简单柱跳灯

  实验场景动态图


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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 09:30:43

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之一:使用MAX9814的音乐反应12位环形灯

  实验视频剪辑

https://v.youku.com/v_show/id_XNTgxMTk5MTM4OA==.html?firsttime=5



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 10:24:05

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之一:使用MAX9814的音乐反应12位环形灯

  实验场景动态图

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 12:23:29

  【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之二:Adafruit_NeoPixel库的音乐可视化环灯

  实验开源代码

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  3.   项目之二:Adafruit_NeoPixel库的音乐可视化环灯
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #define MIC A0 // 麦克风与A0相连接
  7. #define LED_PIN 6 // LED are connected to D6
  8. #define N_PIXELS 12 // Number of LED
  9. #define N 100 //样本数
  10. #define fadeDelay 10 // 淡出量
  11. #define noiseLevel 15 // 降噪下限
  12. Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
  13. int samples[N]; // 存储样本
  14. int periodFactor = 0; // 用于周期计算
  15. int t1 = -1;
  16. int T;
  17. int slope;
  18. byte periodChanged = 0;
  19. void setup() {
  20.   // Serial.begin(9600);
  21.   strip.begin();
  22.   ledsOff();
  23.   delay(500);
  24.   displayColor(Wheel(100));
  25.   strip.show();
  26.   delay(500);
  27. }
  28. void loop() {
  29.   Samples();
  30. }
  31. void Samples() {
  32.   for (int i = 0; i < N; i++) {
  33.     samples[i] = analogRead(0);
  34.     if (i > 0) {
  35.       slope = samples[i] - samples[i - 1];
  36.     }
  37.     else {
  38.       slope = samples[i] - samples[N - 1];
  39.     }
  40.     if (abs(slope) > noiseLevel) {
  41.       if (slope < 0) {
  42.         calculatePeriod(i);
  43.         if (periodChanged == 1) {
  44.           displayColor(getColor(T));
  45.         }
  46.       }
  47.     }
  48.     else {
  49.       ledsOff();
  50.     }
  51.     periodFactor += 1;
  52.     delay(1);
  53.   }
  54. }
  55. void calculatePeriod(int i) {
  56.   if (t1 == -1) {
  57.     t1 = i;
  58.   }
  59.   else {
  60.     int period = periodFactor * (i - t1);
  61.     periodChanged = T == period ? 0 : 1;
  62.     T = period;
  63.     // Serial.println(T);
  64.     t1 = i;
  65.     periodFactor = 0;
  66.   }
  67. }
  68. uint32_t getColor(int period) {
  69.   if (period == -1)
  70.     return Wheel(0);
  71.   else if (period > 400)
  72.     return Wheel(5);
  73.   else
  74.     return Wheel(map(-1 * period, -400, -1, 50, 255));
  75. }
  76. void fadeOut()
  77. {
  78.   for (int i = 0; i < 5; i++) {
  79.     strip.setBrightness(110 - i * 20);
  80.     strip.show(); // Update strip
  81.     delay(fadeDelay);
  82.     periodFactor += fadeDelay;
  83.   }
  84. }
  85. void fadeIn() {
  86.   strip.setBrightness(100);
  87.   strip.show();
  88.   for (int i = 0; i < 5; i++) {
  89.     //strip.setBrightness(20*i + 30);
  90.     //strip.show();
  91.     delay(fadeDelay);
  92.     periodFactor += fadeDelay;
  93.   }
  94. }
  95. void ledsOff() {
  96.   fadeOut();
  97.   for (int i = 0; i < N_PIXELS; i++) {
  98.     strip.setPixelColor(i, 0, 0, 0);
  99.   }
  100. }
  101. void displayColor(uint32_t color) {
  102.   for (int i = 0; i < N_PIXELS; i++) {
  103.     strip.setPixelColor(i, color);
  104.   }
  105.   fadeIn();
  106. }
  107. uint32_t Wheel(byte WheelPos) {
  108.   // Serial.println(WheelPos);
  109.   if (WheelPos < 85) {
  110.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  111.   }
  112.   else if (WheelPos < 170) {
  113.     WheelPos -= 85;
  114.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  115.   }
  116.   else {
  117.     WheelPos -= 170;
  118.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  119.   }
  120. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 12:30:29

【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之二:Adafruit_NeoPixel库的音乐可视化环灯

  实验视频剪辑


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



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 12:40:03

  实验场景 动态图

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 14:35:24

  【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之三:十六位直条WS2812音乐可视化柱灯

  实验开源代码

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  3.   项目之三:十六位直条WS2812音乐可视化柱灯
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #define N_PIXELS  16  // Number of pixels in strand
  7. #define MIC_PIN   A0  // Microphone is attached to this analog pin
  8. #define LED_PIN    6  // NeoPixel LED strand is connected to this pin
  9. #define DC_OFFSET  0  // DC offset in mic signal - if unusure, leave 0
  10. #define NOISE     300  // Noise/hum/interference in mic signal
  11. #define SAMPLES   50  // Length of buffer for dynamic level adjustment
  12. #define TOP       (N_PIXELS + 2) // Allow dot to go slightly off scale
  13. #define PEAK_FALL 60  // Rate of peak falling dot
  14. byte
  15. peak      = 0,      // Used for falling dot
  16. dotCount  = 0,      // Frame counter for delaying dot-falling speed
  17. volCount  = 0;      // Frame counter for storing past volume data
  18. int
  19. vol[SAMPLES],       // Collection of prior volume samples
  20.     lvl       = 100,      // Current "dampened" audio level
  21.     minLvlAvg = 0,      // For dynamic adjustment of graph low & high
  22.     maxLvlAvg = 512;
  23. Adafruit_NeoPixel
  24. strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
  25. void setup() {
  26.   // This is only needed on 5V Arduinos (Uno, Leonardo, etc.).
  27.   // Connect 3.3V to mic AND TO AREF ON ARDUINO and enable this
  28.   // line.  Audio samples are 'cleaner' at 3.3V.
  29.   // COMMENT OUT THIS LINE FOR 3.3V ARDUINOS (FLORA, ETC.):
  30.   
  31.   analogReference(EXTERNAL);
  32.   memset(vol, 0, sizeof(vol));
  33.   strip.setBrightness(66);
  34.   strip.begin();
  35. }
  36. void loop() {
  37.   uint8_t  i;
  38.   uint16_t minLvl, maxLvl;
  39.   int      n, height;
  40.   n   = analogRead(MIC_PIN);   // Raw reading from mic
  41.   n   = abs(n - 512 - DC_OFFSET); // Center on zero
  42.   n   = (n <= NOISE) ? 0 : (n - NOISE);             // Remove noise/hum
  43.   lvl = ((lvl * 7) + n) >> 3;    // "Dampened" reading (else looks twitchy)
  44.   // Calculate bar height based on dynamic min/max levels (fixed point):
  45.   height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg);
  46.   if (height < 0L)       height = 0;     // Clip output
  47.   else if (height > TOP) height = TOP;
  48.   if (height > peak)     peak   = height; // Keep 'peak' dot at top
  49.   // Color pixels based on rainbow gradient
  50.   for (i = 0; i < N_PIXELS; i++) {
  51.     if (i >= height)               strip.setPixelColor(i,   0,   0, 0);
  52.     else strip.setPixelColor(i, Wheel(map(i, 0, strip.numPixels() - 1, 30, 150)));
  53.   }
  54.   // Draw peak dot
  55.   if (peak > 0 && peak <= N_PIXELS - 1) strip.setPixelColor(peak, Wheel(map(peak, 0, strip.numPixels() - 1, 30, 150)));
  56.   strip.show(); // Update strip
  57.   // Every few frames, make the peak pixel drop by 1:
  58.   if (++dotCount >= PEAK_FALL) { //fall rate
  59.     if (peak > 0) peak--;
  60.     dotCount = 0;
  61.   }
  62.   vol[volCount] = n;                      // Save sample for dynamic leveling
  63.   if (++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter
  64.   // Get volume range of prior frames
  65.   minLvl = maxLvl = vol[0];
  66.   for (i = 1; i < SAMPLES; i++) {
  67.     if (vol[i] < minLvl)      minLvl = vol[i];
  68.     else if (vol[i] > maxLvl) maxLvl = vol[i];
  69.   }
  70.   // minLvl and maxLvl indicate the volume range over prior frames, used
  71.   // for vertically scaling the output graph (so it looks interesting
  72.   // regardless of volume level).  If they're too close together though
  73.   // (e.g. at very low volume levels) the graph becomes super coarse
  74.   // and 'jumpy'...so keep some minimum distance between them (this
  75.   // also lets the graph go to zero when no sound is playing):
  76.   if ((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP;
  77.   minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels
  78.   maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average)
  79. }
  80. // Input a value 0 to 255 to get a color value.
  81. // The colors are a transition r - g - b - back to r.
  82. uint32_t Wheel(byte WheelPos) {
  83.   if (WheelPos < 85) {
  84.     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  85.   } else if (WheelPos < 170) {
  86.     WheelPos -= 85;
  87.     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  88.   } else {
  89.     WheelPos -= 170;
  90.     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  91.   }
  92. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 14:46:52

  实验场景图

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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 15:09:24

  【花雕动手做】有趣好玩的音乐可视化系列小项目(05)---WS2812柱跳灯
  项目之三:十六位直条WS2812音乐可视化柱灯

实验视频剪辑


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


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-10-9 15:12:04

实验场景动态图

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

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-5 09:49:00

【花雕动手做】看见声音,基于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


回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail