【花雕动手做】有趣好玩的音乐可视化项目(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 Boot项目

《一文详解如何在idea中快速搭建一个SpringBoot项目》IntelliJIDEA作为Java开发者的‌首选IDE‌,深度集成SpringBoot支持,可一键生成项目骨架、智能配置依赖,这篇文... 目录前言1、创建项目名称2、勾选需要的依赖3、在setting中检查maven4、编写数据源5、开启热

SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志

《SpringBoot项目配置logback-spring.xml屏蔽特定路径的日志》在SpringBoot项目中,使用logback-spring.xml配置屏蔽特定路径的日志有两种常用方式,文中的... 目录方案一:基础配置(直接关闭目标路径日志)方案二:结合 Spring Profile 按环境屏蔽关

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地

springboot项目中使用JOSN解析库的方法

《springboot项目中使用JOSN解析库的方法》JSON,全程是JavaScriptObjectNotation,是一种轻量级的数据交换格式,本文给大家介绍springboot项目中使用JOSN... 目录一、jsON解析简介二、Spring Boot项目中使用JSON解析1、pom.XML文件引入依

Python数据分析与可视化的全面指南(从数据清洗到图表呈现)

《Python数据分析与可视化的全面指南(从数据清洗到图表呈现)》Python是数据分析与可视化领域中最受欢迎的编程语言之一,凭借其丰富的库和工具,Python能够帮助我们快速处理、分析数据并生成高质... 目录一、数据采集与初步探索二、数据清洗的七种武器1. 缺失值处理策略2. 异常值检测与修正3. 数据

基于Python开发一个有趣的工作时长计算器

《基于Python开发一个有趣的工作时长计算器》随着远程办公和弹性工作制的兴起,个人及团队对于工作时长的准确统计需求日益增长,本文将使用Python和PyQt5打造一个工作时长计算器,感兴趣的小伙伴可... 目录概述功能介绍界面展示php软件使用步骤说明代码详解1.窗口初始化与布局2.工作时长计算核心逻辑3

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)

《使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)》字体设计和矢量图形处理是编程中一个有趣且实用的领域,通过Python的matplotlib库,我们可以轻松将字体轮廓... 目录背景知识字体轮廓的表示实现步骤1. 安装依赖库2. 准备数据3. 解析路径指令4. 绘制图形关键

Maven项目中集成数据库文档生成工具的操作步骤

《Maven项目中集成数据库文档生成工具的操作步骤》在Maven项目中,可以通过集成数据库文档生成工具来自动生成数据库文档,本文为大家整理了使用screw-maven-plugin(推荐)的完... 目录1. 添加插件配置到 pom.XML2. 配置数据库信息3. 执行生成命令4. 高级配置选项5. 注意事

eclipse如何运行springboot项目

《eclipse如何运行springboot项目》:本文主要介绍eclipse如何运行springboot项目问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目js录当在eclipse启动spring boot项目时出现问题解决办法1.通过cmd命令行2.在ecl