【花雕动手做】有趣好玩的音乐可视化系列小项目(07)---大方格频谱灯
项目之五:红白绿三色24段三级联频谱大方格灯(FFT算法)
实验开源代码
- /*
- 【花雕动手做】有趣好玩的音乐可视化系列小项目(07)---大方格频谱灯
- 项目之五:红白绿三色24段三级联频谱大方格灯(FFT算法)
- */
-
- #include <arduinoFFT.h>
-
- #include <MD_MAX72xx.h>
-
- #include <SPI.h>
-
- MD_MAX72XX disp = MD_MAX72XX(MD_MAX72XX::FC16_HW, 10, 3);
-
- 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(A0) / 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);
-
- }
-
- }
复制代码
|