|

楼主 |
发表于 2021-11-22 10:49
|
显示全部楼层
【花雕动手做】有趣好玩的音乐可视化系列小项目(08)---四位32段点阵屏
项目之三:红绿色32段级联频谱点阵屏灯(FFT算法)
实验开源代码
- /*
- 【花雕动手做】有趣好玩的音乐可视化系列小项目(08)---四位32段点阵屏
- 项目之三:红绿色32段级联频谱点阵屏灯(FFT算法)
- 接脚连线:MAX9814 接A0
- MAX7219 UNO
- VCC →→→→→ 5V
- GND →→→→→ GND
- DIN →→→→→ D11(数据,数据接收引脚)
- CS →→→→→ D10(负载,命令接收引脚)
- CLK →→→→→ D13(时钟,时钟引脚)
- */
- #include <arduinoFFT.h>
- #include <MD_MAX72xx.h>
- #include <SPI.h>
- MD_MAX72XX disp = MD_MAX72XX(MD_MAX72XX::FC16_HW, 10, 1);
- arduinoFFT FFT = arduinoFFT();
- double realComponent[64];
- double imagComponent[64];
- int spectralHeight[] = {0b00000000, 0b10000000, 0b11000000,
- 0b11100000, 0b11110000, 0b11111000,
- 0b11111100, 0b11111110, 0b11111111
- };
- int index, c, value;
- void setup()
- {
- disp.begin();
- Serial.begin(9600);
- }
- void loop()
- {
- int sensitivity = map(analogRead(A0), 0, 1023, 50, 100);
- Serial.println (analogRead(A0));
- for (int i = 0; i < 64; i++)
- {
- realComponent[i] = analogRead(A7) / sensitivity;
- imagComponent[i] = 0;
- }
- FFT.Windowing(realComponent, 64, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
- FFT.Compute(realComponent, imagComponent, 64, FFT_FORWARD);
- FFT.ComplexToMagnitude(realComponent, imagComponent, 64);
- for (int i = 0; i < 32; i++)
- {
- realComponent[i] = constrain(realComponent[i], 0, 80);
- realComponent[i] = map(realComponent[i], 0, 80, 0, 8);
- index = realComponent[i];
- value = spectralHeight[index];
- c = 31 - i;
- disp.setColumn(c, value);
- }
- }
复制代码
|
|