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

相关文章

Node.js 数据库 CRUD 项目示例详解(完美解决方案)

《Node.js数据库CRUD项目示例详解(完美解决方案)》:本文主要介绍Node.js数据库CRUD项目示例详解(完美解决方案),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考... 目录项目结构1. 初始化项目2. 配置数据库连接 (config/db.js)3. 创建模型 (models/

电脑死机无反应怎么强制重启? 一文读懂方法及注意事项

《电脑死机无反应怎么强制重启?一文读懂方法及注意事项》在日常使用电脑的过程中,我们难免会遇到电脑无法正常启动的情况,本文将详细介绍几种常见的电脑强制开机方法,并探讨在强制开机后应注意的事项,以及如何... 在日常生活和工作中,我们经常会遇到电脑突然无反应的情况,这时候强制重启就成了解决问题的“救命稻草”。那

springboot项目中常用的工具类和api详解

《springboot项目中常用的工具类和api详解》在SpringBoot项目中,开发者通常会依赖一些工具类和API来简化开发、提高效率,以下是一些常用的工具类及其典型应用场景,涵盖Spring原生... 目录1. Spring Framework 自带工具类(1) StringUtils(2) Coll

Spring Boot项目部署命令java -jar的各种参数及作用详解

《SpringBoot项目部署命令java-jar的各种参数及作用详解》:本文主要介绍SpringBoot项目部署命令java-jar的各种参数及作用的相关资料,包括设置内存大小、垃圾回收... 目录前言一、基础命令结构二、常见的 Java 命令参数1. 设置内存大小2. 配置垃圾回收器3. 配置线程栈大小

利用Python快速搭建Markdown笔记发布系统

《利用Python快速搭建Markdown笔记发布系统》这篇文章主要为大家详细介绍了使用Python生态的成熟工具,在30分钟内搭建一个支持Markdown渲染、分类标签、全文搜索的私有化知识发布系统... 目录引言:为什么要自建知识博客一、技术选型:极简主义开发栈二、系统架构设计三、核心代码实现(分步解析

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.

基于Python打造一个可视化FTP服务器

《基于Python打造一个可视化FTP服务器》在日常办公和团队协作中,文件共享是一个不可或缺的需求,所以本文将使用Python+Tkinter+pyftpdlib开发一款可视化FTP服务器,有需要的小... 目录1. 概述2. 功能介绍3. 如何使用4. 代码解析5. 运行效果6.相关源码7. 总结与展望1

C++变换迭代器使用方法小结

《C++变换迭代器使用方法小结》本文主要介绍了C++变换迭代器使用方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录1、源码2、代码解析代码解析:transform_iterator1. transform_iterat

使用Python实现快速搭建本地HTTP服务器

《使用Python实现快速搭建本地HTTP服务器》:本文主要介绍如何使用Python快速搭建本地HTTP服务器,轻松实现一键HTTP文件共享,同时结合二维码技术,让访问更简单,感兴趣的小伙伴可以了... 目录1. 概述2. 快速搭建 HTTP 文件共享服务2.1 核心思路2.2 代码实现2.3 代码解读3.

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s