本文主要是介绍【花雕动手做】有趣好玩的音乐可视化项目(10)---快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
偶然心血来潮,想要做一个声音可视化的系列专题。这个专题的难度有点高,涉及面也比较广泛,相关的FFT和FHT等算法也相当复杂,不过还是打算从最简单的开始,实际动手做做试验,耐心尝试一下各种方案,逐步积累些有用的音乐频谱可视化的资料,也会争取成型一些实用好玩的音乐可视器项目。
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)—WS2812硬板屏
WS2812B主要特点
智能反接保护,电源反接不会损坏IC。
IC控制电路与LED点光源公用一个电源。
控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。
内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。
内置上电复位和掉电复位电路。
每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。
串行级联接口,能通过一根信号线完成数据的接收与解码。
任意两点传传输距离在不超过5米时无需增加任何电路。
当刷新速率30帧/秒时,级联数不小于1024点。
数据发送速度可达800Kbps。
光的颜色高度一致,性价比高。
主要应用领域
LED全彩发光字灯串,LED全彩模组, LED全彩软灯条硬灯条,LED护栏管。
LED点光源,LED像素屏,LED异形屏,各种电子产品,电器设备跑马灯。
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)—WS2812硬板屏
项目之五:快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)
实验开源代码
/*【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏项目之五:快速哈特利变换FHT音乐反应灯板(8X8位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 64 // 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[NUM_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 libraryuint8_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 quietvoid setup() {analogReference(EXTERNAL); // Connect 3.3V to AREF pin for any microphones using 3.3VSerial.begin(9600); // use the serial portLEDS.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[2 * i + 2], noiseval); // Get the sample and subtract the 'quiet' normalized values, but don't go < 0.if (tmp > (leds[i].r + leds[i].g + leds[i].b) / 2) // Refresh an LED only when the intensity is lowleds[i] = 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[i].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[i] = 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()
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)—WS2812硬板屏
项目之五:快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)
实验视频剪辑
https://v.youku.com/v_show/id_XNTgwODY2NzkzMg==.html?spm=a2hcb.playlsit.page.1
实验场景动态图
【花雕动手做】有趣好玩的音乐可视化系列小项目(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[NUM_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 libraryuint8_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 quietvoid setup() {analogReference(EXTERNAL); // Connect 3.3V to AREF pin for any microphones using 3.3VSerial.begin(9600); // use the serial portFastLED.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[2 * i + 2], noiseval); // Get the sample and subtract the 'quiet' normalized values, but don't go < 0.if (tmp > (leds[i].r + leds[i].g + leds[i].b) / 2) // Refresh an LED only when the intensity is lowleds[i] = 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[i].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[i] = 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()
【花雕动手做】有趣好玩的音乐可视化系列小项目(10)—WS2812硬板屏
项目之六:快速哈特利变换FHT音乐反应灯板(8X32位WS2812硬屏)
实验视频剪辑
https://v.youku.com/v_show/id_XNTgyNzY0NTc5Mg==.html?spm=a2hcb.playlsit.page.1
这篇关于【花雕动手做】有趣好玩的音乐可视化项目(10)---快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!