【花雕动手做】有趣好玩的音乐可视化项目(10)---快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)

本文主要是介绍【花雕动手做】有趣好玩的音乐可视化项目(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硬屏)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/186729

相关文章

IDEA运行spring项目时,控制台未出现的解决方案

《IDEA运行spring项目时,控制台未出现的解决方案》文章总结了在使用IDEA运行代码时,控制台未出现的问题和解决方案,问题可能是由于点击图标或重启IDEA后控制台仍未显示,解决方案提供了解决方法... 目录问题分析解决方案总结问题js使用IDEA,点击运行按钮,运行结束,但控制台未出现http://

解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题

《解决IDEA使用springBoot创建项目,lombok标注实体类后编译无报错,但是运行时报错问题》文章详细描述了在使用lombok的@Data注解标注实体类时遇到编译无误但运行时报错的问题,分析... 目录问题分析问题解决方案步骤一步骤二步骤三总结问题使用lombok注解@Data标注实体类,编译时

C语言小项目实战之通讯录功能

《C语言小项目实战之通讯录功能》:本文主要介绍如何设计和实现一个简单的通讯录管理系统,包括联系人信息的存储、增加、删除、查找、修改和排序等功能,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录功能介绍:添加联系人模块显示联系人模块删除联系人模块查找联系人模块修改联系人模块排序联系人模块源代码如下

SpringBoot项目中Maven剔除无用Jar引用的最佳实践

《SpringBoot项目中Maven剔除无用Jar引用的最佳实践》在SpringBoot项目开发中,Maven是最常用的构建工具之一,通过Maven,我们可以轻松地管理项目所需的依赖,而,... 目录1、引言2、Maven 依赖管理的基础概念2.1 什么是 Maven 依赖2.2 Maven 的依赖传递机

Vue项目中Element UI组件未注册的问题原因及解决方法

《Vue项目中ElementUI组件未注册的问题原因及解决方法》在Vue项目中使用ElementUI组件库时,开发者可能会遇到一些常见问题,例如组件未正确注册导致的警告或错误,本文将详细探讨这些问题... 目录引言一、问题背景1.1 错误信息分析1.2 问题原因二、解决方法2.1 全局引入 Element

Python 中 requests 与 aiohttp 在实际项目中的选择策略详解

《Python中requests与aiohttp在实际项目中的选择策略详解》本文主要介绍了Python爬虫开发中常用的两个库requests和aiohttp的使用方法及其区别,通过实际项目案... 目录一、requests 库二、aiohttp 库三、requests 和 aiohttp 的比较四、requ

SpringBoot项目启动后自动加载系统配置的多种实现方式

《SpringBoot项目启动后自动加载系统配置的多种实现方式》:本文主要介绍SpringBoot项目启动后自动加载系统配置的多种实现方式,并通过代码示例讲解的非常详细,对大家的学习或工作有一定的... 目录1. 使用 CommandLineRunner实现方式:2. 使用 ApplicationRunne

Python中的可视化设计与UI界面实现

《Python中的可视化设计与UI界面实现》本文介绍了如何使用Python创建用户界面(UI),包括使用Tkinter、PyQt、Kivy等库进行基本窗口、动态图表和动画效果的实现,通过示例代码,展示... 目录从像素到界面:python带你玩转UI设计示例:使用Tkinter创建一个简单的窗口绘图魔法:用

使用IntelliJ IDEA创建简单的Java Web项目完整步骤

《使用IntelliJIDEA创建简单的JavaWeb项目完整步骤》:本文主要介绍如何使用IntelliJIDEA创建一个简单的JavaWeb项目,实现登录、注册和查看用户列表功能,使用Se... 目录前置准备项目功能实现步骤1. 创建项目2. 配置 Tomcat3. 项目文件结构4. 创建数据库和表5.

Python项目打包部署到服务器的实现

《Python项目打包部署到服务器的实现》本文主要介绍了PyCharm和Ubuntu服务器部署Python项目,包括打包、上传、安装和设置自启动服务的步骤,具有一定的参考价值,感兴趣的可以了解一下... 目录一、准备工作二、项目打包三、部署到服务器四、设置服务自启动一、准备工作开发环境:本文以PyChar