驴友花雕 发表于 2022-10-27 09:56:00

实验的视频记录
优酷:
B站:https://www.bilibili.com/video/BV1L14y157PU/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

https://www.bilibili.com/video/BV1L14y157PU/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

驴友花雕 发表于 2022-11-17 19:06:46

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十七:Wemos D1 R32 ESP32开发板
项目之四十六:基于虚拟轮生成颜色的256位音乐可视化


/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十七:Wemos D1 R32 ESP32开发板
项目之四十六:基于虚拟轮生成颜色的256位音乐可视化
*/

#include <FastLED.h>

// LED LIGHTING SETUP
#define LED_PIN   23
#define NUM_LEDS    256
#define BRIGHTNESS30
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds;

#define UPDATES_PER_SECOND 100

// AUDIO INPUT SETUP
int audio = 38;

// STANDARD VISUALIZER VARIABLES
int loop_max = 0;
int k = 255; // COLOR WHEEL POSITION
int decay = 0; // HOW MANY MS BEFORE ONE LIGHT DECAY
int decay_check = 0;
long pre_react = 0; // NEW SPIKE CONVERSION
long react = 0; // NUMBER OF LEDs BEING LIT
long post_react = 0; // OLD SPIKE CONVERSION

// RAINBOW WAVE SETTINGS
int wheel_speed = 4;

void setup()
{
// LED LIGHTING SETUP
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS );

// CLEAR LEDS
for (int i = 0; i < NUM_LEDS; i++)
    leds = CRGB(0, 0, 0);
FastLED.show();

// SERIAL AND INPUT SETUP
Serial.begin(115200);
pinMode(audio, INPUT);
Serial.println("\nListening...");
}

CRGB Scroll(int pos) {
CRGB color (0,0,0);
if(pos < 85) {
    color.g = 0;
    color.r = ((float)pos / 85.0f) * 255.0f;
    color.b = 255 - color.r;
} else if(pos < 170) {
    color.g = ((float)(pos - 85) / 85.0f) * 255.0f;
    color.r = 255 - color.g;
    color.b = 0;
} else if(pos < 256) {
    color.b = ((float)(pos - 170) / 85.0f) * 255.0f;
    color.g = 255 - color.b;
    color.r = 1;
}
return color;
}

void rainbow(){
for(int i = NUM_LEDS - 1; i >= 0; i--) {
    if (i < react)
      leds = Scroll((i * 256 / 50 + k) % 256);
    else
      leds = CRGB(0, 0, 0);      
}
FastLED.show();
}

void loop(){
int audio_input = analogRead(audio)*5.5; // 在此处调整,以获得更多敏感性

if (audio_input > 0)
{
    pre_react = ((long)NUM_LEDS * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs

    if (pre_react > react) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL
      react = pre_react;

    Serial.print(audio_input);
    Serial.print(" -> ");
    Serial.println(pre_react);
}

rainbow(); // APPLY COLOR

k = k - wheel_speed; // SPEED OF COLOR WHEEL
if (k < 0) // RESET COLOR WHEEL
    k = 255;

// REMOVE LEDs
decay_check++;
if (decay_check > decay)
{
    decay_check = 0;
    if (react > 0)
      react--;
}
delay(1);
}

驴友花雕 发表于 2022-11-17 19:11:37

实验场景图动态图



驴友花雕 发表于 2022-11-17 19:20:32

实验的视频记录
优酷:https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1
B站:https://www.bilibili.com/video/B ... 87403d97f8d3cc0b7e5

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

驴友花雕 发表于 2022-11-17 20:01:51

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十七:Wemos D1 R32 ESP32开发板
项目之四十七:快速傅里叶变换256位频谱仪

/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百七十七:Wemos D1 R32 ESP32开发板
项目之四十七:快速傅里叶变换256位频谱仪
*/

#include"arduinoFFT.h"
#include <FastLED.h>   

#define NUM_LEDS 256   
#define LED_TYPE WS2812
#define COLOR_ORDER GRB

arduinoFFT FFT = arduinoFFT();
CRGB leds;         

#define CHANNEL 39
#define DATA_PIN 23

const uint8_t max_bright = 2;         
const uint16_t samples = NUM_LEDS / 4;
const byte halfsamples = samples / 2;
uint8_t gHue;                        
int value;                           
double vReal;               
double vImag;               
char toData;            

int pointJump;
int uJump;   
int dJump;   

int uValue;               
int dValue;               
int tValue;               
int toDown = 0;            
uint8_t toDownSpeed = 3;   
int pointDown = 0;         
uint8_t pointDownSpeed = 9;

void setup(){
delay(100);            
Serial.println("Ready");
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(max_bright);
}

void loop(){
FastLED.clear();                        
EVERY_N_MILLISECONDS(10) {
    gHue += 10;
}
for (int i = 0; i < samples; i++)      
{
    value = analogRead(CHANNEL);
    vReal = value;      
    vImag = 0.0;         
}

FFT.Windowing(vReal, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
FFT.Compute(vReal, vImag, samples, FFT_FORWARD);
FFT.ComplexToMagnitude(vReal, vImag, samples);

for (int i = 0; i < halfsamples; i++)
{
    toData = vReal;   
    toData = constrain(toData, 0, 100);
    toData = map(toData, 0, 100, 1, 7);
}
for (int i = 0; i < halfsamples; i++)
{
    uValue = toData;   
    uJump++;            
    if (uValue > uJump)
    {
      uValue = uJump;
    }
    else
    {
      uJump = uValue;
    }
    dValue = uValue;
    toDown++;                     
    if (toDown % toDownSpeed == 0)
    {
      dJump--;
      toDown = 0;
    }
    if (dValue > pointJump)
    {
      dJump = dValue;
    }
    else
    {
      dValue = dJump;
    }
    tValue = uValue;                     
    pointDown++;                        
    if (pointDown % pointDownSpeed == 0)
    {
      pointJump--;
      pointDown = 0;
    }
    if (tValue > pointJump)
    {
      pointJump = tValue;
    }
    else
    {
      tValue = pointJump;
    }
    fill_rainbow(leds + 8 * i, uValue, gHue, 30);
    fill_rainbow(leds + 8 * i, dValue, gHue, 30);
    fill_solid(leds + 8 * i + tValue, 1, CRGB::White);
   
}
FastLED.show();
delay(2);      
}

驴友花雕 发表于 2022-11-17 20:19:06

实验场景图



驴友花雕 发表于 2022-11-17 20:27:01

实验的视频记录
优酷:https://v.youku.com/v_show/id_XNTkxOTQxODA2OA==.html?spm=a2hcb.playlsit.page.3
B站:https://www.bilibili.com/video/BV1ye4y1s7n1/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

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

驴友花雕 发表于 2022-11-17 20:32:35

实验场景图动态图



驴友花雕 发表于 2022-11-17 21:17:12

实验的视频记录
优酷:https://v.youku.com/v_show/id_XNTkxOTQxODEzNg==.html?spm=a2hcb.playlsit.page.1
B站:https://www.bilibili.com/video/BV1hg411q7yo/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

https://www.bilibili.com/video/BV1hg411q7yo/?vd_source=98c6b1fc23b2787403d97f8d3cc0b7e5

页: 1 2 [3]
查看完整版本: 【花雕动手做】看见声音,基于Arduino系列音乐可视器(10)