【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试-Arduino中文社区 - Powered by Discuz! Archiver

eagler8 发表于 2022-7-20 09:33

【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
实验程序三:点亮LED—WS2812FX自动模式循环20种

/*
【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
实验程序三:点亮LED—WS2812FX自动模式循环20种
模块接线:WS2812B接D9
MAX9814   ESP32_C3
VCC          5V
GND         GND
OUT       D4(ADC4)
*/

#include <WS2812FX.h>

#define LED_COUNT 256
#define LED_PIN    9

#define TIMER_MS 5000

WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

unsigned long last_change = 0;
unsigned long now = 0;

void setup() {
ws2812fx.init();
ws2812fx.setBrightness(28);
ws2812fx.setSpeed(1000);
ws2812fx.setColor(0x007BFF);
ws2812fx.setMode(FX_MODE_STATIC);
ws2812fx.start();
}

void loop() {
now = millis();
ws2812fx.service();
if(now - last_change > TIMER_MS) {
    ws2812fx.setMode((ws2812fx.getMode() + 1) % ws2812fx.getModeCount());
    last_change = now;
}
}

eagler8 发表于 2022-7-20 09:53

实验场景图



eagler8 发表于 2022-7-20 11:15

实验的视频记录


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

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

eagler8 发表于 2022-7-20 20:40

【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
实验程序四:MegunoLink音乐反应式LED灯带
模块接线:WS2812B接D9
MAX9814   ESP32_C3
VCC          5V
GND         GND
OUT       D4(ADC4)

/*
【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试
实验程序四:MegunoLink音乐反应式LED灯带
模块接线:WS2812B接D9
MAX9814   ESP32_C3
VCC          5V
GND         GND
OUT       D4(ADC4)
*/

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

// define necessary parameters
#define N_PIXELS24
#define MIC_PIN   4
#define LED_PIN   9
// the following parameters can be tweaked according to your audio levels
#define NOISE 150
#define TOP   (N_PIXELS+2) // allow the max level to be slightly off scale
#define LED_TYPEWS2811
#define BRIGHTNESS18   // a little dim for recording purposes
#define COLOR_ORDER GRB

// declare the LED array
CRGB leds;

// define the variables needed for the audio levels
int lvl = 0, minLvl = 0, maxLvl = 100; // tweak the min and max as needed

// instantiate the filter class for smoothing the raw audio signal
ExponentialFilter<long> ADCFilter(5,0);

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// initialize the LED object
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,N_PIXELS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}

void loop() {
// put your main code here, to run repeatedly:
// read the audio signal and filter it
int n, height;
n = analogRead(MIC_PIN);
// remove the MX9614 bias of 1.25VDC
n = abs(1023 - n);
// hard limit noise/hum
n = (n <= NOISE) ? 0 : abs(n - NOISE);
// apply the exponential filter to smooth the raw signal
ADCFilter.Filter(n);
lvl = ADCFilter.Current();
//// plot the raw versus filtered signals
//Serial.print(n);
//Serial.print(" ");
//Serial.println(lvl);
// calculate the number of pixels as a percentage of the range
// TO-DO: can be done dynamically by using a running average of min/max audio levels
height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
if(height < 0L) height = 0;
else if(height > TOP) height = TOP;
// turn the LEDs corresponding to the level on/off
for(uint8_t i = 0; i < N_PIXELS; i++) {
    // turn off LEDs above the current level
    if(i >= height) leds = CRGB(0,0,0);
    // otherwise, turn them on!
    else leds = Wheel( map( i, 0, N_PIXELS-1, 30, 150 ) );
}
FastLED.show();
}

CRGB Wheel(byte WheelPos) {
// return a color value based on an input value between 0 and 255
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);
}
}

eagler8 发表于 2022-7-20 21:05

实验场景图动态图 https://img.mydigit.cn/forum/202207/20/210229ghbzxeexqjauhchc.gif


eagler8 发表于 2022-7-20 21:50

本帖最后由 eagler8 于 2022-7-21 09:13 编辑

实验的视频记录(21秒)

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

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


eagler8 发表于 2022-7-21 09:28

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


https://v.youku.com/v_show/id_XNTg4ODI4Nzc1Mg==.html?spm=a2hcb.playlsit.page.5

https://v.youku.com/v_show/id_XNTg4ODI4Nzc1Mg==.html?spm=a2hcb.playlsit.page.7
页: 1 2 [3]
查看完整版本: 【花雕体验】20 音乐可视化:ESP32_C3与WS2812B的系列尝试