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

【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤 简单

头像 驴友花雕 2022.09.17 123 2

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

前面已经尝试了二种光导纤维,这次我找到了一个新的品种,叫闪点光纤(也称为打点水帘光纤),包括直径1mm的四十米,3合1 的十米(单根直径也是1mm)。

project-image

3合1闪点光导纤维

project-image

3合1闪点光导纤维

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

光纤灯的底座准备使用几个瓶盖的组合

project-image

WS2812B采用四位模块、八位模块和十二位模块

project-image

WS2812B
是一种将控制电路和rgb芯片集成在一起的智能控制led光源。5050组件的包装。内部包括智能数字端口数据锁存和信号整形放大驱动电路。还包括精密内部振荡器和12V电压可编程恒流控制部分,有效保证了像素点光色高度一致。数据传输协议采用单NZR通信方式。像素上电复位后,DIN端口接收数据来自控制器,第一个像素收集初始24位数据,然后发送到内部数据锁存器,其他数据由内部信号整形放大电路通过DO端口发送到下一个级联像素进行整形。后对于每个像素的传输,信号要减少24位。像素采用自动整形传输技术,使像素级联数不受信号传输的限制,只取决于信号传输的速度。复位时间>280μs,中断时不会造成误复位,支持较低频率,价格低廉单片机。刷新频率更新到2kHz,画面频率低,高清摄像机无闪烁,提高出色的展示效果。LED具有驱动电压低、环保节能、亮度高、散射角大、一致性好、功率低、寿命长等优点。集成在led上的控制芯片越来越多电路简单,体积小,安装方便。

project-image

WS2812B电原理图

project-image

组合好的WS2812B模块

project-image

安装到光纤灯底座上

project-image

1mm闪点光纤40米切段

project-image

三合一闪点光纤10米的切段

project-image

光纤束捆

project-image

闪点光纤灯基本成型了

project-image
project-image

【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
项目程序之一:绿色单灯循环测试
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  项目程序之一:绿色单灯循环测试
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          D7
*/

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define MAX_LED 24

#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, 100, 0);

  while (a < 25)
  {
    for (i = 0; i < 24; i++)
    {
      if (i == a) strip.setPixelColor(i, color);
      else strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(200);
    a++;
  }
}

实验场景图 动态图

project-image

实验场景图

project-image

【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
项目程序之二:闪点光纤灯简易流动变色测试
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  项目程序之二:闪点光纤灯简易流动变色测试
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          D7
*/

#include <FastLED.h>
#define LED_PIN     6
#define NUM_LEDS    24
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}

void loop() {
  for (int i = 0; i <= 23; i++) {
    leds[i] = CRGB ( 0, 0, 255);
    FastLED.show();
    delay(200);
  }
  for (int i = 23; i >= 0; i--) {
    leds[i] = CRGB ( 255, 0, 0);
    FastLED.show();
    delay(200);
  }
  for (int i = 0; i <= 23; i++) {
    leds[i] = CRGB ( 0, 255, 0);
    FastLED.show();
    delay(200);
  }
}

实验场景图

project-image

实验的视频记录

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

【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
项目程序之三:FastLED音乐反应节奏灯
模块接线:WS2812B接D6
MAX4466 UNO
VCC 5V
GND GND
OUT D7

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  项目程序之三:FastLED音乐反应节奏灯
  模块接线:WS2812B接D6
  MAX4466      UNO
  VCC          5V
  GND         GND
  OUT          D7
*/

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

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++;
  }
}

实验的视频记录

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

【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯 '

项目程序之四:NeoPixel 测试程序

代码
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  项目程序之四: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 24

// 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), 50); // Red
  colorWipe(strip.Color(  0, 255,   0), 50); // Green
  colorWipe(strip.Color(  0,   0, 255), 50); // Blue

  // Do a theater marquee effect in various colors...
  theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  theaterChase(strip.Color(  0,   0, 127), 50); // 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(wait);                           //  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 < 10; 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(wait);  // 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 < 5 * 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(wait);  // 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(wait);                 // Pause for a moment
      firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
    }
  }
}

实验场景图 动态图

project-image

实验的视频记录

https://v.youku.com/v_show/id_XNTkwMjczNTA3Mg==.html?spm=a2hcb.playlsit.page.3

 【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯

 实验程序五:Adafruit_NeoPixel音乐反应式LED灯

代码
 【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
 实验程序五:Adafruit_NeoPixel音乐反应式LED灯
*/

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

#define N_PIXELS  60
#define MIC_PIN   A0
#define LED_PIN   6
#define NOISE 10
#define TOP   (N_PIXELS+2)
#define LED_TYPE  WS2811
#define BRIGHTNESS  10
#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);
  }
}

实验的视频记录(4分40秒)

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

实验场景图

project-image

评论

user-avatar
  • 三春牛-创客

    三春牛-创客2023.01.19

    赞!!!

    0
    • 三春牛-创客

      三春牛-创客2023.01.19

      厉害厉害

      0
      icon 他的勋章
        展开更多