回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页
best-icon

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯 简单

头像 驴友花雕 2022.09.19 80 3

偶然心血来潮,想要做一个音乐可视化的系列专题。这个专题的难度有点高,涉及面也比较广泛,相关的FFT和FHT等算法也相当复杂,不过还是打算从最简单的开始,实际动手做做试验,耐心尝试一下各种方案,逐步积累些有用的音乐频谱可视化的资料,也会争取成型一些实用好玩的音乐可视器项目。

找到一只标准规格的吊顶平板灯,还有一个黑色铝材相框,准备制作二种稍大尺寸的无限镜子灯(也叫时光隧道灯,无限镜面延伸镜子深渊灯)。

project-image
project-image

在音乐可视化系列之中,项目20(见前序列)曾将一个十公分大小的首饰盒,制作为迷你的镜子灯,其反射的效果一般,是个初步的尝试。

project-image

维基百科上是这样定义的,无限反射镜是一种有两面或多面镜子组成的复合结构,这些镜子通常互相平行或接近平行。这种结构可以在镜子中产生无限多的虚像,以越来越小的姿态延伸至无限“远”。这种结构经常用单向玻璃做前面的镜子,但不用单向玻璃也可以达成效果。在艺术作品中,画面本身出现在画面中,再出现在画面中的画面中,称作德罗斯特效应。无限反射镜有时会用于室内装潢或艺术创作。(见https://zh.m.wikipedia.org/zh-hans/无限反射镜)

草间弥生(YayoiKusama)是世界上最有影响力的当代艺术家之一,于1929年出生于日本松本。 这位90岁的艺术家以其雕塑和装置而闻名,最著名的是她的《无限镜室》。30年后,草间弥生的无限镜作品终于火了,她于1965年创作了第一个无限镜作品: Phalli's Field。

草间弥生在大约25平方米充满镜子的房间中布置了数百种柔软的形式,作者兼策展人凯瑟琳·塔夫脱(Catherine Taft)在新近出版的草间弥生传中写道。“要与这些毛绒的凸起物产生互动,而这些通过无限反射数量倍增,这一切包围了观察者,创造了一种 与自己的身体和想象在心理上的相遇 。”

project-image

一套经典而完整的无限反射镜,一般都含有一组灯泡、LED灯或其他点光源,镶嵌在反射镜的整个边缘,同时一面部分反射的单向玻璃会以极近的距离被固定在反射镜前,彼此以互相平行的姿态对齐。当外部的观察者看向单向玻璃面时,光会在镜中延伸至无限,使镜看起来像是一条极深邃的隧道。如果两面镜子没有精确平行,而是存在微小的夹角,那么这条虚拟的隧道就会向镜的某一边弯曲并无限延伸。

无限反射镜的效果,也可以采取别的结构实现。观察者站在两面互相平行的全反射镜面中间时亦可以观察到此现象,某些试衣间、电梯和镜子迷宫会采取这种装潢。除了经过精心设计的装潢外,在站在两个互相平行且均带有反射效果的平面间时,也能看到弱化版的无限反射,比如饰有玻璃墙的走廊或小厅。部分反射的玻璃可以产生这种现象,而在通过玻璃渗入环境的视觉噪点作用下逐渐削弱。当站在两面镜子中间,场景见下图。

project-image

一套经典而完整的无限反射镜,一般都含有一组灯泡、LED灯或其他点光源,镶嵌在反射镜的整个边缘,同时一面部分反射的单向玻璃会以极近的距离被固定在反射镜前,彼此以互相平行的姿态对齐。当外部的观察者看向单向玻璃面时,光会在镜中延伸至无限,使镜看起来像是一条极深邃的隧道。如果两面镜子没有精确平行,而是存在微小的夹角,那么这条虚拟的隧道就会向镜的某一边弯曲并无限延伸。

无限反射镜的效果,也可以采取别的结构实现。观察者站在两面互相平行的全反射镜面中间时亦可以观察到此现象,某些试衣间、电梯和镜子迷宫会采取这种装潢。除了经过精心设计的装潢外,在站在两个互相平行且均带有反射效果的平面间时,也能看到弱化版的无限反射,比如饰有玻璃墙的走廊或小厅。部分反射的玻璃可以产生这种现象,而在通过玻璃渗入环境的视觉噪点作用下逐渐削弱。当站在两面镜子中间,场景见下图。

project-image

视觉艺术家,尤其是当代艺术家雕刻家 ,已使用无穷大反射镜。 草间弥生, 乔西亚·麦克埃里尼(Josiah McElheny), 伊万·纳瓦罗(Ivan Navarro), 泰勒·戴维斯(Taylor Davis) , 和 安东尼·詹姆斯所有作品都使用无限反射镜扩大了作品中无限空间的感觉。

一些游乐园黑暗的游乐设施 ,例如迪士尼的“太空山 云霄飞车,使用无限反射镜营造出在太空中飞行的印象。

当代古典作曲家 阿尔沃·派特(ArvoPärt) 写了他1978年的作品 Spiegel im Spiegel (“镜子中的镜子”)作为对无限镜子效果的音乐反射。

星球大战:最后的绝地武士 包括一个具有无限镜面效果的短洞穴场景片段。

project-image

又找到一种规格小些的相框

project-image

声音模块,使用性价比更高的MAX4466声音传感器。

MAX4466模块特点
电源电压:+2.4V至+5.5V(可直接接STM/ARDUNIO/树莓派等开发板)
电源抑制比:112dB
共模抑制比:126dB
AVOL:125dB(RL = 100kΩ) 轨到轨输出
静态电源电流:24μA
增益带宽:600kHz
尺寸:20.8mm x 13.8mm x 7.5mm/0.8 x 0.5 x 0.3inch

project-image

MAX4466
是微功率运算放大器,经过优化,可用作麦克风前置放大器。它们提供了优化的增益带宽产品与电源电流的理想组合,以及超小型封装中实现低电压工件环境。 MAX4466具有增益稳定特性,仅需24μA的电源电流即可提供200kHz的增益带宽。经过解压缩,可实现+5V/V的最小稳定增益,并提供600KHZ增益带宽。此外这些放大器具有轨到轨输出,高 AVOL ,以及出色的电源抑制和共模抑制比,适合在嘈杂环境中工作。广泛应用于蜂窝电话、数字复读装置、耳机、助听器、麦克风前置放大器、便携计算机和语音识别系统中。

project-image

该模块在 Vcc 和接地引线上都包含铁氧体,以最大限度地减少电源噪声。如果与 MCU 一起使用,最好使用 2.4V – 5.5V 范围内可用的最安静的电源。在 Arduino 上,这通常是 3.3V 电源。

输出是直流耦合的。当输出信号处于静止状态时,它将位于 Vcc/2。如果 Vcc 为 5V,则输出将为 2.5V。如果输出需要交流耦合,可以在输出引脚和它驱动的电路的输入之间增加一个100uF的电容。

背面的小型单圈电位器可让您将增益从 25x 调整到 125x。逆时针旋转电位器会增加增益,而逆时针旋转会降低增益。

project-image

采用每米60灯黑底裸板

project-image

WS2812B

是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。

project-image

主要特点
1、智能反接保护,电源反接不会损坏IC。
2、IC控制电路与LED点光源公用一个电源。
3、控制电路与RGB芯片集成在一个5050封装的元器件中,构成一个完整的外控像素点。
4、内置信号整形电路,任何一个像素点收到信号后经过波形整形再输出,保证线路波形畸变不会累加。
5、内置上电复位和掉电复位电路。
6、每个像素点的三基色颜色可实现256级亮度显示,完成16777216种颜色的全真色彩显示,扫描频率不低于400Hz/s。
7、串行级联接口,能通过一根信号线完成数据的接收与解码。
8、任意两点传传输距离在不超过5米时无需增加任何电路。
9、当刷新速率30帧/秒时,级联数不小于1024点。
10、数据发送速度可达800Kbps。
11、光的颜色高度一致,性价比高。

应用领域
具有低电压驱动,环保节能,亮度高,散射角度大,一致性好,超低功率,超长寿命等优点。将控制电路集成于LED上面,电路变得更加简单,体积小,安装更加简便。主要应用领域,LED全彩发光字灯串,LED全彩模组, LED全彩软灯条硬灯条,LED护栏管。LED点光源,LED像素屏,LED异形屏,各种电子产品,电器设备跑马灯等。

project-image
project-image
project-image

WS2812B灯带电原理图

project-image

WS2812B是集控制电路和发光电路于一体的LED光源元件,其控制IC为WS2812B,发光元件是5050RGBLED,电压为5V,每个单位的峰值电流为60ma,灯带为三线制,VCC GND DIN分别为电源+、电源-、信号,当使用外部电源时,外部电源-需要与单片机的GND相连。

project-image
project-image

铝材相框

project-image

安装了WS2812B灯带

project-image

使用玻璃贴膜

project-image

贴膜技术有点逊,有待于后续能有提高.......

project-image

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯

项目程序之一:点亮ws2812灯带LED

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之一:点亮ws2812灯带LED
*/

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define MAX_LED 62

#define ADD true
#define SUB false

int val = 0;
boolean stat = ADD;

Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );

void setup()
{
  strip.begin();           
  strip.show();           
}

void loop()
{
  uint8_t i,a=0;                                        
  uint32_t color = strip.Color(255, 0, 0);         
  while(a<63)
  {
      for(i=0;i<62;i++)
      {
        if(i==a) strip.setPixelColor(i, color);     
        else strip.setPixelColor(i, 0);             
      }
       strip.show();                                
       delay(3);                                   
       a++;                                         
  }
}

实验场景图 动态图

project-image

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯

项目程序之二:NeoPixel Ring 绿色灯

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之二:NeoPixel Ring 绿色灯
*/

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN        6 // On Trinket or Gemma, suggest changing this to 1

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 62 // Popular NeoPixel ring size

// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.
  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop() {
  pixels.clear(); // Set all pixel colors to 'off'

  // The first NeoPixel in a strand is #0, second is 1, all the way up
  // to the count of pixels minus one.
  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...

    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    // Here we're using a moderately bright green color:
    pixels.setPixelColor(i, pixels.Color(250, 250, 250));

    pixels.show();   // Send the updated pixel colors to the hardware.

    delay(6); // Pause before next pass through loop
  }
}

实验场景图

project-image

实验的视频记录

https://v.youku.com/v_show/id_XNTkwMzQ1MjkxMg==.html?spm=a2hcb.playlsit.page.1

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯

项目程序之三:NeoPixel 环形灯条测试程序

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之三:NeoPixel 环形灯条测试程序
*/

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 62

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)


// setup() function -- runs once at startup --------------------------------

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(250); // Set BRIGHTNESS to about 1/5 (max = 255)
}


// loop() function -- runs repeatedly as long as board is on ---------------

void loop() {
  // Fill along the length of the strip in various colors...
  colorWipe(strip.Color(255,   0,   0), 250); // Red
  colorWipe(strip.Color(  0, 255,   0), 250); // Green
  colorWipe(strip.Color(  0,   0, 255), 250); // Blue

  // Do a theater marquee effect in various colors...
  theaterChase(strip.Color(127, 127, 127), 250); // White, half brightness
  theaterChase(strip.Color(127,   0,   0), 250); // Red, half brightness
  theaterChase(strip.Color(  0,   0, 127), 250); // Blue, half brightness

  rainbow(10);             // Flowing rainbow cycle along the whole strip
  theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
}


// Some functions of our own for creating animated effects -----------------

// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    strip.show();                          //  Update strip to match
    delay(30);                           //  Pause for a moment
  }
}

// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
// between frames.
void theaterChase(uint32_t color, int wait) {
  for (int a = 0; a < 20; a++) { // Repeat 10 times...
    for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
      // 'c' counts up from 'b' to end of strip in steps of 3...
      for (int c = b; c < strip.numPixels(); c += 3) {
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show(); // Update strip with new contents
      delay(30);  // Pause for a moment
    }
  }
}

// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  for (long firstPixelHue = 0; firstPixelHue < 2 * 65536; firstPixelHue += 256) {
    for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    delay(2);  // Pause for a moment
  }
}

// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {
  int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  for (int a = 0; a < 30; a++) { // Repeat 30 times...
    for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
      strip.clear();         //   Set all pixels in RAM to 0 (off)
      // 'c' counts up from 'b' to end of strip in increments of 3...
      for (int c = b; c < strip.numPixels(); c += 3) {
        // hue of pixel 'c' is offset by an amount to make one full
        // revolution of the color wheel (range 65536) along the length
        // of the strip (strip.numPixels() steps):
        int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
        uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
        strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
      }
      strip.show();                // Update strip with new contents
      delay(50);                 // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}

实验的视频记录

优酷:https://v.youku.com/v_show/id_XNTkwNTEyNjIwMA==.html?spm=a2hcb.playlsit.page.1

B站:https://www.bilibili.com/video/BV1ng41127VE/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

实验场景图

project-image
project-image

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯

  项目程序之四:FastLED音乐反应节奏灯

  模块接线:WS2812B接D6

  MAX4466      UNO

  VCC          5V

  GND         GND

  OUT          A0

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之四:FastLED音乐反应节奏灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0
*/

#include<FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 62

CRGB leds[NUM_LEDS];
uint8_t hue = 0;
int soundsensor = A0;

void setup() {
  delay(3000);
  FastLED.setBrightness(255);
  pinMode(soundsensor, INPUT);
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}

void loop() {
  int sensval = digitalRead(soundsensor);

  if (sensval == 1) {
    leds[0] = CRGB :: Red;
    fill_solid(leds, NUM_LEDS, CRGB :: Blue);
    rainbow_moving();
    FastLED.show();
    delay(100);
  }
  else {
    leds[0] = CRGB :: Black;
    fill_solid(leds, NUM_LEDS, CRGB :: Black);
    FastLED.show();
    delay(100);
  }
}

void rainbow_moving() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue + (i * 10), 255, 255);
  }
  EVERY_N_MILLISECONDS(10) {
    hue++;
  }
}

实验场景图  动态图

 

动画78.gif

实验的视频记录

 

优酷:https://v.youku.com/v_show/id_XNTkwNTEzOTYyNA==.html?spm=a2hcb.playlsit.page.1

 

B站:https://www.bilibili.com/video/BV1314y1a7wP/?spm_id_from=333.999.0.0&vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

实验场景图

 


30.jpg

  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯

  项目之五:Arduino 和 FastLED多彩音乐节拍灯

  模块接线:WS2812B接D6

  MAX4466      UNO

  VCC          5V

  GND         GND

  OUT          A0

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目之五:Arduino 和 FastLED多彩音乐节拍灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0
*/

#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 62
uint8_t max_bright = 255;
struct CRGB leds[NUM_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[3] = {0, 0, 0}, yv[3] = {0, 0, 0};
  xv[0] = xv[1]; xv[1] = xv[2];
  xv[2] = sample / 9.1f;
  yv[0] = yv[1]; yv[1] = yv[2];
  yv[2] = (xv[2] - xv[0]) + (-0.7960060012f * yv[0]) + (1.7903124146f * yv[1]);
  return yv[2];
}

float envelopeFilter(float sample) {
  static float xv[2] = {0, 0}, yv[2] = {0, 0};
  xv[0] = xv[1];
  xv[1] = sample / 160.f;
  yv[0] = yv[1];
  yv[1] = (xv[0] + xv[1]) + (0.9875119299f * yv[0]);
  return yv[1];
}

float beatFilter(float sample) {
  static float xv[3] = {0, 0, 0}, yv[3] = {0, 0, 0};
  xv[0] = xv[1]; xv[1] = xv[2];
  xv[2] = sample / 7.015f;
  yv[0] = yv[1]; yv[1] = yv[2];
  yv[2] = (xv[2] - xv[0]) + (-0.7169861741f * yv[0]) + (1.4453653501f * yv[1]);
  return yv[2];
}

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 * 62) + sample) / 63;
    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[i] = 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, 62);
      FastLED.show();
    }

    for (unsigned long up = time + SAMPLEPERIODUS; time > 20 && time < up; time = micros()) {  }

  } // for i
} // loop()

实验的视频记录

 

优酷:https://v.youku.com/v_show/id_XNTkwNjc1MTYyOA==.html?spm=a2hcb.playlsit.page.1

 

B站:https://www.bilibili.com/video/BV1Vg411e768/?spm_id_from=444.41.list.card_archive.click&vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之六:多彩MegunoLink音乐节拍灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0

代码
/*
【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之六:多彩MegunoLink音乐节拍灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          A0
*/

#include<FastLED.h>
#include<MegunoLink.h>
#include<Filter.h>

#define N_PIXELS 120
#define MIC_PIN A0
#define LED_PIN 6
#define NOISE 10
#define TOP (N_PIXELS+2)
#define LED_TYPE WS2811
#define BRIGHTNESS 22
#define COLOR_ORDER GRB

CRGB leds[N_PIXELS];
int lvl = 0, minLvl = 0, maxLvl = 10;

ExponentialFilter<long> ADCFilter(5, 0);

void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, N_PIXELS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
int n, height;
n = analogRead(MIC_PIN);
n = abs(1023 - n);
n = (n <= NOISE) ? 0 : abs(n - NOISE);
ADCFilter.Filter(n);
lvl = ADCFilter.Current();
// Serial.print(n);
// Serial.print(" ");
// Serial.println(lvl);
height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
if (height < 0L) height = 0;
else if (height > TOP) height = TOP;
for (uint8_t i = 0; i < N_PIXELS; i++) {
if (i >= height) leds[i] = CRGB(0, 0, 0);
else leds[i] = Wheel( map( i, 0, N_PIXELS - 1, 30, 150 ) );
}
FastLED.show();
}

CRGB Wheel(byte WheelPos) {
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);
}
}

实验的视频记录

 

优酷:https://v.youku.com/v_show/id_XNTkwNjc2NzM0MA==.html?spm=a2hcb.playlsit.page.1

 

B站:https://www.bilibili.com/video/BV1qV4y1T7bo/?spm_id_from=333.999.0.0&vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

评论

user-avatar
  • 三春牛-创客

    三春牛-创客2023.01.17

    赞!

    0
    • 三春牛-创客

      三春牛-创客2023.01.17

      厉害厉害

      0
      • 匿名

        匿名

        该评论已删除

        1
        • 驴友花雕

          驴友花雕2023.06.18

          谢谢鼓励

      icon 他的勋章
        展开更多