3386

帖子

0

TA的资源

五彩晶圆(中级)

21
 

 【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏

  项目之四:256位全彩闪动音乐频谱灯(8x32位WS2812硬屏)

 

  实验视频剪辑

 

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

 


 

 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

22
 

  实验场景动态图

 

 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

23
 

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


uint8_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 quiet

void setup() {
  analogReference(EXTERNAL);                                  // Connect 3.3V to AREF pin for any microphones using 3.3V
  Serial.begin(9600);                                        // use the serial port

  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 low
      leds[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()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

24
 

 【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏

  项目之五:快速哈特利变换FHT音乐反应灯板(8X8位WS2812硬屏)

 

  实验视频剪辑

 

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

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

25
 

  实验场景动态图

 

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

26
 

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


uint8_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 quiet

void setup() {
  analogReference(EXTERNAL);                                  // Connect 3.3V to AREF pin for any microphones using 3.3V
  Serial.begin(9600);                                        // use the serial port
  FastLED.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 low
      leds[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()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

27
 

 【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏

  项目之六:快速哈特利变换FHT音乐反应灯板(8X32位WS2812硬屏)

 

  实验视频剪辑

 

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

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

28
 

  实验场景动态图

 

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

29
 

  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之七:基于虚拟轮生成颜色的音乐可视化(8X32位 WS2812硬屏)

 

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之七:基于虚拟轮生成颜色的音乐可视化(8X32位 WS2812硬屏)
*/

#include <FastLED.h>

// LED LIGHTING SETUP
#define LED_PIN     6
#define NUM_LEDS    480
#define BRIGHTNESS  30
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

// AUDIO INPUT SETUP
int audio = A0;

// 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[i] = 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[i] = Scroll((i * 256 / 50 + k) % 256);
    else
      leds[i] = CRGB(0, 0, 0);      
  }
  FastLED.show(); 
}

void loop()
{
  int audio_input = analogRead(audio); // ADD x2 HERE FOR MORE SENSITIVITY  

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

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

30
 

实验场景图  动态图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

31
 

  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之八:通过快速傅里叶变换在ws2812b8*8灯板上显示频谱

 

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之八:通过快速傅里叶变换在ws2812b8*8灯板上显示频谱
*/

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

#define NUM_LEDS 64    
#define LED_TYPE WS2812 
#define COLOR_ORDER GRB 

arduinoFFT FFT = arduinoFFT(); 
CRGB leds[NUM_LEDS];           

#define CHANNEL A0 
#define DATA_PIN 6 

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[samples];                 
double vImag[samples];                 
char toData[halfsamples];              

int pointJump[halfsamples]; 
int uJump[halfsamples];     
int dJump[halfsamples];    

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[i] = value;       
    vImag[i] = 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[i] = vReal[i + halfsamples / 2];   
    toData[i] = constrain(toData[i], 0, 100); 
    toData[i] = map(toData[i], 0, 100, 1, 7); 
  }
  for (int i = 0; i < halfsamples; i++) 
  {
    uValue = toData[i];    
    uJump[i]++;            
    if (uValue > uJump[i]) 
    {
      uValue = uJump[i]; 
    }
    else
    {
      uJump[i] = uValue;
    }
    dValue = uValue; 
    toDown++;                      
    if (toDown % toDownSpeed == 0) 
    {
      dJump[i]--; 
      toDown = 0; 
    }
    if (dValue > pointJump[i]) 
    {
      dJump[i] = dValue; 
    }
    else
    {
      dValue = dJump[i]; 
    }
    tValue = uValue;                     
    pointDown++;                         
    if (pointDown % pointDownSpeed == 0) 
    {
      pointJump[i]--; 
      pointDown = 0;  
    }
    if (tValue > pointJump[i]) 
    {
      pointJump[i] = tValue; 
    }
    else
    {
      tValue = pointJump[i]; 
    }
    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(10);      
}

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

32
 

实验场景图  动态图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

33
 

实验的视频记录

 

 

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

 

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

34
 

  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之九:FastLED多彩音乐节奏屏灯

 

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之九:FastLED多彩音乐节奏屏灯
*/

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

// define necessary parameters
#define N_PIXELS  64
#define MIC_PIN   A0
#define LED_PIN   6
// the following parameters can be tweaked according to your audio levels
#define NOISE 240
#define TOP   (N_PIXELS+2) // allow the max level to be slightly off scale
#define LED_TYPE  WS2811
#define BRIGHTNESS  34     // a little dim for recording purposes
#define COLOR_ORDER GRB

// declare the LED array
CRGB leds[N_PIXELS];

// define the variables needed for the audio levels
int lvl = 0, minLvl = 0, maxLvl = 300; // 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[i] = CRGB(0, 0, 0);
    // otherwise, turn them on!
    else leds[i] = 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);
  }
}

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

35
 

实验场景图  动态图

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

36
 

实验的视频记录

 

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

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

37
 

  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏

  项目之十:Arduino 和 FastLED多彩音乐灯

 

/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(10)---WS2812硬板屏
  项目之十:Arduino 和 FastLED多彩音乐灯
*/

#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 256
uint8_t max_bright = 33;
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 * 67) + sample) / 68;
    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, 64);
      FastLED.show();
    }

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

  } // for i
} // loop()

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

38
 

实验的视频记录

优酷:

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

 


 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

39
 

  【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 BRIGHTNESS  30
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_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[i] = 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[i] = Scroll((i * 256 / 50 + k) % 256);
    else
      leds[i] = 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);
}

 

 
 
 

回复

3386

帖子

0

TA的资源

五彩晶圆(中级)

40
 

实验场景图  动态图

 

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表