驴友花雕
发表于 2021-12-15 20:10:22
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之五:快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)
实验视频剪辑
https://v.youku.com/v_show/id_XNTgwODY2NzkzMg==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTgwODY2NzkzMg==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2021-12-16 11:04:32
实验场景动态图
驴友花雕
发表于 2021-12-16 11:34:13
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之六:快速哈特利变换FHT音乐反应灯板(8X32位WS2812硬屏)
实验开源代码
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之六:快速哈特利变换FHT音乐反应灯板(8X32位 WS2812硬屏)
*/
#define qsubd(x, b) ((x>b)?wavebright:0) // A digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b) ((x>b)?x-b:0) // Unsigned subtraction macro. if result <0, then => 0.
#define wavebright 128 // qsubd result will be this value if subtraction is >0.
#include "FastLED.h" // FastLED library. Preferably the latest copy of FastLED 2.1.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// Fixed definitions cannot change on the fly.
#define LED_DT 6 // Data pin to connect to the strip.
//#define LED_CK 11 // Clock pin for APA102 or WS2801
#define COLOR_ORDER GRB // It's GRB for WS2812
#define LED_TYPE WS2812B // What kind of strip are you using (APA102, WS2801 or WS2812B)
#define NUM_LEDS 256 // Number of LED's.
// Initialize changeable global variables.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
struct CRGB leds; // Initialize our LED array.
#define LOG_OUT 1
#define FHT_N 256 // Set to 256 point fht.
#define inputPin A0
//#define potPin A4
#include <FHT.h> // FHT library
uint8_t hueinc = 0; // A hue increment value to make it rotate a bit.
uint8_t micmult = 25;
uint8_t fadetime = 900;
uint8_t noiseval = 25; // Increase this to reduce sensitivity. 30 seems best for quiet
void setup() {
analogReference(EXTERNAL); // Connect 3.3V to AREF pin for any microphones using 3.3V
Serial.begin(9600); // use the serial port
FastLED.setBrightness (22);
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
//LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
set_max_power_in_volts_and_milliamps(5, 300); // FastLED Power management set at 5V, 500mA.
}
void loop() {
// noiseval = map(analogRead(potPin), 0, 1023, 16, 48); // Adjust sensitivity of cutoff.
EVERY_N_MILLISECONDS(13) {
fhtsound();
}
show_at_max_brightness_for_power();
Serial.println(LEDS.getFPS(), DEC); // Display frames per second on the serial monitor.
Serial.println(" "); // Display frames per second on the serial monitor.
Serial.println(analogRead(inputPin)); // print as an ASCII-encoded decimal */
}
void fhtsound() {
// hueinc++; // A cute little hue incrementer.
GetFHT(); // Let's take FHT_N samples and crunch 'em.
for (int i = 0; i < NUM_LEDS; i++) { // Run through the LED array.
int tmp = qsuba(fht_log_out, noiseval); // Get the sample and subtract the 'quiet' normalized values, but don't go < 0.
if (tmp > (leds.r + leds.g + leds.b) / 2) // Refresh an LED only when the intensity is low
leds = CHSV((i * 4) + tmp * micmult, 255, tmp * micmult); // Note how we really cranked up the tmp value to get BRIGHT LED's. Also increment the hue for fun.
leds.nscale8(fadetime); // Let's fade the whole thing over time as well.
}
} // fhtsound()
void GetFHT() {
cli();
for (int i = 0 ; i < FHT_N ; i++) fht_input = analogRead(inputPin);
sei();
fht_window(); // Window the data for better frequency response.
fht_reorder(); // Reorder the data before doing the fht.
fht_run(); // Process the data in the fht.
fht_mag_log();
} // GetFHT()
驴友花雕
发表于 2021-12-16 11:37:28
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之六:快速哈特利变换FHT音乐反应灯板(8X32位WS2812硬屏)
实验视频剪辑
https://v.youku.com/v_show/id_XNTgyNzY0NTc5Mg==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTgyNzY0NTc5Mg==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2021-12-16 11:39:06
实验场景动态图
鹏3
发表于 2021-12-17 10:11:35
#include <FHT.h> // include the library这个库文件哪里下载呢
驴友花雕
发表于 2021-12-17 17:34:49
鹏3 发表于 2021-12-17 10:11
#include// include the library这个库文件哪里下载呢
在这里下载
https://github.com/Evg33/ArduinoFHT
QQQQQQQ
发表于 2022-1-12 20:49:24
好厉害!!!!!!!!!!!!!!!!!!!!
驴友花雕
发表于 2022-1-13 06:20:29
QQQQQQQ 发表于 2022-1-12 20:49
好厉害!!!!!!!!!!!!!!!!!!!!
早上好,谢谢鼓励
QQQQQQQ
发表于 2022-2-11 17:50:19
驴友花雕 发表于 2022-1-13 06:20
早上好,谢谢鼓励
你也好。
驴友花雕
发表于 2022-2-12 21:56:09
QQQQQQQ 发表于 2022-2-11 17:50
你也好。
晚上好,有空多交流
驴友花雕
发表于 2022-7-10 13:23:27
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之七:基于虚拟轮生成颜色的音乐可视化(8X32位 WS2812硬屏)
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之七:基于虚拟轮生成颜色的音乐可视化(8X32位 WS2812硬屏)
*/
#include <FastLED.h>
// LED LIGHTING SETUP
#define LED_PIN 6
#define NUM_LEDS 480
#define BRIGHTNESS30
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds;
#define UPDATES_PER_SECOND 100
// AUDIO INPUT SETUP
int audio = A0;
// STANDARD VISUALIZER VARIABLES
int loop_max = 0;
int k = 255; // COLOR WHEEL POSITION
int decay = 0; // HOW MANY MS BEFORE ONE LIGHT DECAY
int decay_check = 0;
long pre_react = 0; // NEW SPIKE CONVERSION
long react = 0; // NUMBER OF LEDs BEING LIT
long post_react = 0; // OLD SPIKE CONVERSION
// RAINBOW WAVE SETTINGS
int wheel_speed = 4;
void setup()
{
// LED LIGHTING SETUP
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS );
// CLEAR LEDS
for (int i = 0; i < NUM_LEDS; i++)
leds = CRGB(0, 0, 0);
FastLED.show();
// SERIAL AND INPUT SETUP
Serial.begin(115200);
pinMode(audio, INPUT);
Serial.println("\nListening...");
}
CRGB Scroll(int pos) {
CRGB color (0,0,0);
if(pos < 85) {
color.g = 0;
color.r = ((float)pos / 85.0f) * 255.0f;
color.b = 255 - color.r;
} else if(pos < 170) {
color.g = ((float)(pos - 85) / 85.0f) * 255.0f;
color.r = 255 - color.g;
color.b = 0;
} else if(pos < 256) {
color.b = ((float)(pos - 170) / 85.0f) * 255.0f;
color.g = 255 - color.b;
color.r = 1;
}
return color;
}
void rainbow(){
for(int i = NUM_LEDS - 1; i >= 0; i--) {
if (i < react)
leds = Scroll((i * 256 / 50 + k) % 256);
else
leds = CRGB(0, 0, 0);
}
FastLED.show();
}
void loop()
{
int audio_input = analogRead(audio); // ADD x2 HERE FOR MORE SENSITIVITY
if (audio_input > 0)
{
pre_react = ((long)NUM_LEDS * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs
if (pre_react > react) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL
react = pre_react;
Serial.print(audio_input);
Serial.print(" -> ");
Serial.println(pre_react);
}
rainbow(); // APPLY COLOR
k = k - wheel_speed; // SPEED OF COLOR WHEEL
if (k < 0) // RESET COLOR WHEEL
k = 255;
// REMOVE LEDs
decay_check++;
if (decay_check > decay)
{
decay_check = 0;
if (react > 0)
react--;
}
//delay(1);
}
驴友花雕
发表于 2022-7-10 13:25:29
实验场景图动态图
驴友花雕
发表于 2022-7-10 17:22:59
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之八:通过快速傅里叶变换在ws2812b8*8灯板上显示频谱
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之八:通过快速傅里叶变换在ws2812b8*8灯板上显示频谱
*/
#include"arduinoFFT.h"
#include <FastLED.h>
#define NUM_LEDS 64
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
arduinoFFT FFT = arduinoFFT();
CRGB leds;
#define CHANNEL A0
#define DATA_PIN 6
const uint8_t max_bright = 2;
const uint16_t samples = NUM_LEDS / 4;
const byte halfsamples = samples / 2;
uint8_t gHue;
int value;
double vReal;
double vImag;
char toData;
int pointJump;
int uJump;
int dJump;
int uValue;
int dValue;
int tValue;
int toDown = 0;
uint8_t toDownSpeed = 3;
int pointDown = 0;
uint8_t pointDownSpeed = 9;
void setup(){
delay(100);
Serial.println("Ready");
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(max_bright);
}
void loop(){
FastLED.clear();
EVERY_N_MILLISECONDS(10) {
gHue += 10;
}
for (int i = 0; i < samples; i++)
{
value = analogRead(CHANNEL);
vReal = value;
vImag = 0.0;
}
FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, samples, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, samples);
for (int i = 0; i < halfsamples; i++)
{
toData = vReal;
toData = constrain(toData, 0, 100);
toData = map(toData, 0, 100, 1, 7);
}
for (int i = 0; i < halfsamples; i++)
{
uValue = toData;
uJump++;
if (uValue > uJump)
{
uValue = uJump;
}
else
{
uJump = uValue;
}
dValue = uValue;
toDown++;
if (toDown % toDownSpeed == 0)
{
dJump--;
toDown = 0;
}
if (dValue > pointJump)
{
dJump = dValue;
}
else
{
dValue = dJump;
}
tValue = uValue;
pointDown++;
if (pointDown % pointDownSpeed == 0)
{
pointJump--;
pointDown = 0;
}
if (tValue > pointJump)
{
pointJump = tValue;
}
else
{
tValue = pointJump;
}
fill_rainbow(leds + 8 * i, uValue, gHue, 30);
fill_rainbow(leds + 8 * i, dValue, gHue, 30);
fill_solid(leds + 8 * i + tValue, 1, CRGB::White);
}
FastLED.show();
delay(10);
}
驴友花雕
发表于 2022-7-10 17:24:31
实验场景图动态图
驴友花雕
发表于 2022-7-10 18:32:01
实验的视频记录
https://v.youku.com/v_show/id_XNTg4NTc5NDk1Mg==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTg4NTc5NDk1Mg==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2022-7-20 13:42:28
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之九:FastLED多彩音乐节奏屏灯
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之九:FastLED多彩音乐节奏屏灯
*/
#include<FastLED.h>
#include<MegunoLink.h>
#include<Filter.h>
// define necessary parameters
#define N_PIXELS64
#define MIC_PIN A0
#define LED_PIN 6
// the following parameters can be tweaked according to your audio levels
#define NOISE 240
#define TOP (N_PIXELS+2) // allow the max level to be slightly off scale
#define LED_TYPEWS2811
#define BRIGHTNESS34 // a little dim for recording purposes
#define COLOR_ORDER GRB
// declare the LED array
CRGB leds;
// define the variables needed for the audio levels
int lvl = 0, minLvl = 0, maxLvl = 300; // tweak the min and max as needed
// instantiate the filter class for smoothing the raw audio signal
ExponentialFilter<long> ADCFilter(5, 0);
void setup() {
// put your setup code here, to run once:
// Serial.begin(115200);
// initialize the LED object
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, N_PIXELS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
// put your main code here, to run repeatedly:
// read the audio signal and filter it
int n, height;
n = analogRead(MIC_PIN);
// remove the MX9614 bias of 1.25VDC
n = abs(1023 - n);
// hard limit noise/hum
n = (n <= NOISE) ? 0 : abs(n - NOISE);
// apply the exponential filter to smooth the raw signal
ADCFilter.Filter(n);
lvl = ADCFilter.Current();
//// plot the raw versus filtered signals
//Serial.print(n);
//Serial.print(" ");
//Serial.println(lvl);
// calculate the number of pixels as a percentage of the range
// TO-DO: can be done dynamically by using a running average of min/max audio levels
height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
if (height < 0L) height = 0;
else if (height > TOP) height = TOP;
// turn the LEDs corresponding to the level on/off
for (uint8_t i = 0; i < N_PIXELS; i++) {
// turn off LEDs above the current level
if (i >= height) leds = CRGB(0, 0, 0);
// otherwise, turn them on!
else leds = Wheel( map( i, 0, N_PIXELS - 1, 30, 150 ) );
}
FastLED.show();
}
CRGB Wheel(byte WheelPos) {
// return a color value based on an input value between 0 and 255
if (WheelPos < 85)
return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
else if (WheelPos < 170) {
WheelPos -= 85;
return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
驴友花雕
发表于 2022-7-20 13:54:12
实验场景图动态图
驴友花雕
发表于 2022-7-20 14:00:22
实验的视频记录
https://v.youku.com/v_show/id_XNTg4ODE1MTMyMA==.html?spm=a2hcb.playlsit.page.1
https://v.youku.com/v_show/id_XNTg4ODE1MTMyMA==.html?spm=a2hcb.playlsit.page.1
驴友花雕
发表于 2022-10-5 09:56:59
【花雕动手做】看见声音,基于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
驴友花雕
发表于 2022-10-27 09:47:09
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之十:Arduino 和 FastLED多彩音乐灯
/*
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
项目之十:Arduino 和 FastLED多彩音乐灯
*/
#include <FastLED.h>
#define SAMPLEPERIODUS 200
#define MIC_PIN A0
#define LED_DT 6
#define COLOR_ORDER GRB
#define LED_TYPE WS2812
#define NUM_LEDS 256
uint8_t max_bright = 33;
struct CRGB leds;
CRGBPalette16 currentPalette = RainbowColors_p;
CRGBPalette16 targetPalette;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(max_bright);
}
float bassFilter(float sample) {
static float xv = {0, 0, 0}, yv = {0, 0, 0};
xv = xv; xv = xv;
xv = sample / 9.1f;
yv = yv; yv = yv;
yv = (xv - xv) + (-0.7960060012f * yv) + (1.7903124146f * yv);
return yv;
}
float envelopeFilter(float sample) {
static float xv = {0, 0}, yv = {0, 0};
xv = xv;
xv = sample / 160.f;
yv = yv;
yv = (xv + xv) + (0.9875119299f * yv);
return yv;
}
float beatFilter(float sample) {
static float xv = {0, 0, 0}, yv = {0, 0, 0};
xv = xv; xv = xv;
xv = sample / 7.015f;
yv = yv; yv = yv;
yv = (xv - xv) + (-0.7169861741f * yv) + (1.4453653501f * yv);
return yv;
}
void loop() {
unsigned long time = micros();
float sample, value, envelope, beat, thresh, micLev;
for (uint8_t i = 0; ; ++i) {
sample = (float)analogRead(MIC_PIN);
micLev = ((micLev * 67) + sample) / 68;
sample -= micLev;
value = bassFilter(sample);
value = abs(value);
envelope = envelopeFilter(value);
if (i == 200) {
beat = beatFilter(envelope);
thresh = 0.02f * 75.;
if (beat > thresh) {
digitalWrite(LED_BUILTIN, LOW);
int strt = random8(NUM_LEDS / 2);
int ende = strt + random8(NUM_LEDS / 2);
for (int i = strt; i < ende; i++) {
uint8_t index = inoise8(i * 30, millis() + i * 30);
leds = ColorFromPalette(currentPalette, index, 255, LINEARBLEND);
}
} else {
digitalWrite(LED_BUILTIN, HIGH);
}
i = 0;
}
EVERY_N_SECONDS(5) {
uint8_t baseC = random8();
targetPalette = CRGBPalette16(CHSV(baseC + random8(32), 255, random8(128, 255)),
CHSV(baseC + random8(64), 255, random8(128, 255)),
CHSV(baseC + random8(64), 192, random8(128, 255)),
CHSV(baseC + random8(), 255, random8(128, 255)));
}
EVERY_N_MILLISECONDS(50) {
uint8_t maxChanges = 24;
nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges);
}
EVERY_N_MILLIS(50) {
fadeToBlackBy(leds, NUM_LEDS, 64);
FastLED.show();
}
for (unsigned long up = time + SAMPLEPERIODUS; time > 20 && time < up; time = micros()) {}
} // for i
} // loop()