9102浏览
查看: 9102|回复: 45

[项目] 【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)

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

正好手头还有四片8X8硬屏,于是把它们拼在一起,组成一块16X16的WS2812B硬屏,继续尝试音乐可视化的项目。

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 18:38:36

  【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  项目之四:256位音乐频谱灯

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  3.   项目之四:256位音乐频谱灯
  4. */
  5. #include "FastLED.h"
  6. #define OCTAVE 1 //   // Group buckets into octaves  (use the log output function LOG_OUT 1)
  7. #define OCT_NORM 0 // Don't normalise octave intensities by number of bins
  8. #define FHT_N 256 // set to 256 point fht
  9. #include <FHT.h> // include the library
  10. //int noise[] = {204,188,68,73,150,98,88,68}; // noise level determined by playing pink noise and seeing levels [trial and error]{204,188,68,73,150,98,88,68}
  11. // int noise[] = {204,190,108,85,65,65,55,60}; // noise for mega adk
  12. int noise[] = {204, 195, 100, 90, 85, 80, 75, 75}; // noise for NANO
  13. //int noise[] = {204,198,100,85,85,80,80,80};
  14. float noise_fact[] = {15, 7, 1.5, 1, 1.2, 1.4, 1.7, 3}; // noise level determined by playing pink noise and seeing levels [trial and error]{204,188,68,73,150,98,88,68}
  15. float noise_fact_adj[] = {15, 7, 1.5, 1, 1.2, 1.4, 1.7, 3}; // noise level determined by playing pink noise and seeing levels [trial and error]{204,188,68,73,150,98,88,68}
  16. #define LED_PIN     6
  17. #define LED_TYPE    WS2812
  18. #define COLOR_ORDER GRB
  19. // Params for width and height
  20. const uint8_t kMatrixWidth = 8;
  21. const uint8_t kMatrixHeight = 32;
  22. //#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
  23. #define NUM_LEDS    256
  24. CRGB leds[NUM_LEDS];
  25. int counter2 = 0;
  26. void setup() {
  27.   Serial.begin(9600);
  28.   delay(1000);
  29.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  30.   FastLED.setBrightness (33);
  31.   fill_solid(leds, NUM_LEDS, CRGB::Black);
  32.   FastLED.show();
  33.   // TIMSK0 = 0; // turn off timer0 for lower jitter
  34.   ADCSRA = 0xe5; // set the adc to free running mode
  35.   ADMUX = 0x40; // use adc0
  36.   DIDR0 = 0x01; // turn off the digital input for adc0
  37. }
  38. void loop() {
  39.   int prev_j[8];
  40.   int beat = 0;
  41.   int prev_oct_j;
  42.   int counter = 0;
  43.   int prev_beat = 0;
  44.   int led_index = 0;
  45.   int saturation = 0;
  46.   int saturation_prev = 0;
  47.   int brightness = 0;
  48.   int brightness_prev = 0;
  49.   while (1) { // reduces jitter
  50.     cli();  // UDRE interrupt slows this way down on arduino1.0
  51.     for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
  52.       while (!(ADCSRA & 0x10)); // wait for adc to be ready
  53.       ADCSRA = 0xf5; // restart adc
  54.       byte m = ADCL; // fetch adc data
  55.       byte j = ADCH;
  56.       int k = (j << 8) | m; // form into an int
  57.       k -= 0x0200; // form into a signed int
  58.       k <<= 6; // form into a 16b signed int
  59.       fht_input[i] = k; // put real data into bins
  60.     }
  61.     fht_window(); // window the data for better frequency response
  62.     fht_reorder(); // reorder the data before doing the fht
  63.     fht_run(); // process the data in the fht
  64.     fht_mag_octave(); // take the output of the fht  fht_mag_log()
  65.     // every 50th loop, adjust the volume accourding to the value on A2 (Pot)
  66.     if (counter >= 50) {
  67.       ADMUX = 0x40 | (1 & 0x07); // set admux to look at Analogpin A1 - Master Volume
  68.       while (!(ADCSRA & 0x10)); // wait for adc to be ready
  69.       ADCSRA = 0xf5; // restart adc
  70.       delay(10);
  71.       while (!(ADCSRA & 0x10)); // wait for adc to be ready
  72.       ADCSRA = 0xf5; // restart adc
  73.       byte m = ADCL; // fetch adc data
  74.       byte j = ADCH;
  75.       int k = (j << 8) | m; // form into an int
  76.       float master_volume = (k + 0.1) / 1000 + .75; // so the valu will be between ~0.5 and 1.---------------------+.75 was .5
  77.       Serial.println (master_volume);
  78.       for (int i = 1; i < 8; i++) {
  79.         noise_fact_adj[i] = noise_fact[i] * master_volume;
  80.       }
  81.       ADMUX = 0x40 | (0 & 0x07); // set admux back to look at A0 analog pin (to read the microphone input
  82.       counter = 0;
  83.     }
  84.     sei();
  85.     counter++;
  86.     // End of Fourier Transform code - output is stored in fht_oct_out[i].
  87.     // i=0-7 frequency (octave) bins (don't use 0 or 1), fht_oct_out[1]= amplitude of frequency for bin 1
  88.     // for loop a) removes background noise average and takes absolute value b) low / high pass filter as still very noisy
  89.     // c) maps amplitude of octave to a colour between blue and red d) sets pixel colour to amplitude of each frequency (octave)
  90.     for (int i = 1; i < 8; i++) {  // goes through each octave. skip the first 1, which is not useful
  91.       int j;
  92.       j = (fht_oct_out[i] - noise[i]); // take the pink noise average level out, take the asbolute value to avoid negative numbers
  93.       if (j < 10) {
  94.         j = 0;
  95.       }
  96.       j = j * noise_fact_adj[i];
  97.       if (j < 10) {
  98.         j = 0;
  99.       }
  100.       else {
  101.         j = j * noise_fact_adj[i];
  102.         if (j > 180) {
  103.           if (i >= 7) {
  104.             beat += 2;
  105.           }
  106.           else {
  107.             beat += 1;
  108.           }
  109.         }
  110.         j = j / 30;
  111.         j = j * 30; // (force it to more discrete values)
  112.       }
  113.       prev_j[i] = j;
  114.       //     Serial.print(j);
  115.       //     Serial.print(" ");
  116.       // this fills in 11 LED's with interpolated values between each of the 8 OCT values
  117.       if (i >= 2) {
  118.         led_index = 2 * i - 3;
  119.         prev_oct_j = (j + prev_j[i - 1]) / 2;
  120.         saturation = constrain(j + 50, 0, 255); //-----------50 was 30
  121.         saturation_prev = constrain(prev_oct_j + 50, 0, 255);
  122.         brightness = constrain(j, 0, 255);
  123.         brightness_prev = constrain(prev_oct_j, 0, 255);
  124.         if (brightness == 255) {
  125.           saturation = 50;
  126.           brightness = 200;
  127.         }
  128.         if (brightness_prev == 255) {
  129.           saturation_prev = 50;
  130.           brightness_prev = 200;
  131.         }
  132.         for (uint8_t y = 0; y < kMatrixHeight; y++) {
  133.           leds[XY(led_index - 1, y)] = CHSV(j + y * 30, saturation, brightness);
  134.           if (i > 2) {
  135.             prev_oct_j = (j + prev_j[i - 1]) / 2;
  136.             leds[ XY(led_index - 2, y)] = CHSV(prev_oct_j + y * 30, saturation_prev, brightness_prev);
  137.           }
  138.         }
  139.       }
  140.     }
  141.     if (beat >= 7) {
  142.       fill_solid(leds, NUM_LEDS, CRGB::Gray);
  143.       FastLED.setBrightness(200);
  144.     }
  145.     else {
  146.       if (prev_beat != beat) {
  147.         FastLED.setBrightness(40 + beat * beat * 5);
  148.         prev_beat = beat;
  149.       }
  150.     }
  151.     FastLED.show();
  152.     if (beat) {
  153.       counter2 += ((beat + 4) / 2 - 2);
  154.       if (counter2 < 0) {
  155.         counter2 = 1000;
  156.       }
  157.       if (beat > 3 && beat < 7) {
  158.         FastLED.delay (20);
  159.       }
  160.       beat = 0;
  161.     }
  162.     // Serial.println();
  163.   }
  164. }
  165. // Param for different pixel layouts
  166. const bool    kMatrixSerpentineLayout = false;
  167. // Set 'kMatrixSerpentineLayout' to false if your pixels are
  168. // laid out all running the same way, like this:
  169. // Set 'kMatrixSerpentineLayout' to true if your pixels are
  170. // laid out back-and-forth, like this:
  171. uint16_t XY( uint8_t x, uint8_t y)
  172. {
  173.   uint16_t i;
  174.   if ( kMatrixSerpentineLayout == false) {
  175.     i = (y * kMatrixWidth) + x;
  176.   }
  177.   if ( kMatrixSerpentineLayout == true) {
  178.     if ( y & 0x01) {
  179.       // Odd rows run backwards
  180.       uint8_t reverseX = (kMatrixWidth - 1) - x;
  181.       i = (y * kMatrixWidth) + reverseX;
  182.     } else {
  183.       // Even rows run forwards
  184.       i = (y * kMatrixWidth) + x;
  185.     }
  186.   }
  187.   i = (i + counter2) % NUM_LEDS;
  188.   return i;
  189. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 10:18:55

  【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
   项目之二:RGB传输测试满屏变幻彩灯

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  3.   项目之二:RGB传输测试满屏变幻彩灯
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #ifdef __AVR__
  7. #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
  8. #endif
  9. // Which pin on the Arduino is connected to the NeoPixels?
  10. // On a Trinket or Gemma we suggest changing this to 1:
  11. #define LED_PIN     6
  12. // How many NeoPixels are attached to the Arduino?
  13. #define LED_COUNT  256
  14. // NeoPixel brightness, 0 (min) to 255 (max)
  15. #define BRIGHTNESS 30
  16. // Declare our NeoPixel strip object:
  17. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
  18. // Argument 1 = Number of pixels in NeoPixel strip
  19. // Argument 2 = Arduino pin number (most are valid)
  20. // Argument 3 = Pixel type flags, add together as needed:
  21. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  22. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  23. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  24. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  25. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  26. void setup() {
  27.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  28.   // Any other board, you can remove this part (but no harm leaving it):
  29. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  30.   clock_prescale_set(clock_div_1);
  31. #endif
  32.   // END of Trinket-specific code.
  33.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  34.   strip.show();            // Turn OFF all pixels ASAP
  35.   strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
  36. }
  37. void loop() {
  38.   // Fill along the length of the strip in various colors...
  39.   colorWipe(strip.Color(255,   0,   0)     , 50); // Red
  40.   colorWipe(strip.Color(  0, 255,   0)     , 50); // Green
  41.   colorWipe(strip.Color(  0,   0, 255)     , 50); // Blue
  42.   colorWipe(strip.Color(  0,   0,   0, 255), 50); // True white (not RGB white)
  43.   whiteOverRainbow(75, 5);
  44.   pulseWhite(5);
  45.   rainbowFade2White(3, 3, 1);
  46. }
  47. // Fill strip pixels one after another with a color. Strip is NOT cleared
  48. // first; anything there will be covered pixel by pixel. Pass in color
  49. // (as a single 'packed' 32-bit value, which you can get by calling
  50. // strip.Color(red, green, blue) as shown in the loop() function above),
  51. // and a delay time (in milliseconds) between pixels.
  52. void colorWipe(uint32_t color, int wait) {
  53.   for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  54.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  55.     strip.show();                          //  Update strip to match
  56.     delay(3);                           //  Pause for a moment
  57.   }
  58. }
  59. void whiteOverRainbow(int whiteSpeed, int whiteLength) {
  60.   if(whiteLength >= strip.numPixels()) whiteLength = strip.numPixels() - 1;
  61.   int      head          = whiteLength - 1;
  62.   int      tail          = 0;
  63.   int      loops         = 3;
  64.   int      loopNum       = 0;
  65.   uint32_t lastTime      = millis();
  66.   uint32_t firstPixelHue = 0;
  67.   for(;;) { // Repeat forever (or until a 'break' or 'return')
  68.     for(int i=0; i<strip.numPixels(); i++) {  // For each pixel in strip...
  69.       if(((i >= tail) && (i <= head)) ||      //  If between head & tail...
  70.          ((tail > head) && ((i >= tail) || (i <= head)))) {
  71.         strip.setPixelColor(i, strip.Color(0, 0, 0, 255)); // Set white
  72.       } else {                                             // else set rainbow
  73.         int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  74.         strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  75.       }
  76.     }
  77.     strip.show(); // Update strip with new contents
  78.     // There's no delay here, it just runs full-tilt until the timer and
  79.     // counter combination below runs out.
  80.     firstPixelHue += 40; // Advance just a little along the color wheel
  81.     if((millis() - lastTime) > whiteSpeed) { // Time to update head/tail?
  82.       if(++head >= strip.numPixels()) {      // Advance head, wrap around
  83.         head = 0;
  84.         if(++loopNum >= loops) return;
  85.       }
  86.       if(++tail >= strip.numPixels()) {      // Advance tail, wrap around
  87.         tail = 0;
  88.       }
  89.       lastTime = millis();                   // Save time of last movement
  90.     }
  91.   }
  92. }
  93. void pulseWhite(uint8_t wait) {
  94.   for(int j=0; j<256; j++) { // Ramp up from 0 to 255
  95.     // Fill entire strip with white at gamma-corrected brightness level 'j':
  96.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  97.     strip.show();
  98.     delay(3);
  99.   }
  100.   for(int j=255; j>=0; j--) { // Ramp down from 255 to 0
  101.     strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  102.     strip.show();
  103.     delay(3);
  104.   }
  105. }
  106. void rainbowFade2White(int wait, int rainbowLoops, int whiteLoops) {
  107.   int fadeVal=0, fadeMax=100;
  108.   // Hue of first pixel runs 'rainbowLoops' complete loops through the color
  109.   // wheel. Color wheel has a range of 65536 but it's OK if we roll over, so
  110.   // just count from 0 to rainbowLoops*65536, using steps of 256 so we
  111.   // advance around the wheel at a decent clip.
  112.   for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536;
  113.     firstPixelHue += 256) {
  114.     for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  115.       // Offset pixel hue by an amount to make one full revolution of the
  116.       // color wheel (range of 65536) along the length of the strip
  117.       // (strip.numPixels() steps):
  118.       uint32_t pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  119.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  120.       // optionally add saturation and value (brightness) (each 0 to 255).
  121.       // Here we're using just the three-argument variant, though the
  122.       // second value (saturation) is a constant 255.
  123.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue, 255,
  124.         255 * fadeVal / fadeMax)));
  125.     }
  126.     strip.show();
  127.     delay(3);
  128.     if(firstPixelHue < 65536) {                              // First loop,
  129.       if(fadeVal < fadeMax) fadeVal++;                       // fade in
  130.     } else if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { // Last loop,
  131.       if(fadeVal > 0) fadeVal--;                             // fade out
  132.     } else {
  133.       fadeVal = fadeMax; // Interim loop, make sure fade is at max
  134.     }
  135.   }
  136.   for(int k=0; k<whiteLoops; k++) {
  137.     for(int j=0; j<256; j++) { // Ramp up 0 to 255
  138.       // Fill entire strip with white at gamma-corrected brightness level 'j':
  139.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  140.       strip.show();
  141.     }
  142.     delay(100); // Pause 1 second
  143.     for(int j=255; j>=0; j--) { // Ramp down 255 to 0
  144.       strip.fill(strip.Color(0, 0, 0, strip.gamma8(j)));
  145.       strip.show();
  146.     }
  147.   }
  148.   delay(5); // Pause 1/2 second
  149. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-11-7 17:58:52

Arduino 系列传感器和执行器模块实验目录清单:
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
https://mc.dfrobot.com.cn/thread-280845-1-1.html
连杆形式的腿机构十一种:盘点机器人行走背后的机械原理
https://mc.dfrobot.com.cn/thread-308097-1-1.html
【花雕动手做】超低成本,尝试五十元的麦克纳姆轮小车!
https://mc.dfrobot.com.cn/thread-307863-1-1.html
【花雕动手做】超迷你哦,用徽商香烟盒做个智能小车!
https://mc.dfrobot.com.cn/thread-307907-1-1.html
【花雕动手做】太搞笑啦,一支胶管制成二只蠕动机器人
https://mc.dfrobot.com.cn/thread-308046-1-1.html
【花雕动手做】快餐盒盖,极低成本搭建机器人实验平台
https://mc.dfrobot.com.cn/thread-308063-1-1.html
【花雕动手做】特别苗条,使用微波传感器控制的纤细小车
https://mc.dfrobot.com.cn/thread-308866-1-1.html
【花雕动手做】脑洞大开、五花八门的简易机器人66种
https://mc.dfrobot.com.cn/thread-307900-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(1)---LED节奏灯
https://mc.dfrobot.com.cn/thread-311167-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(2)---OLED频谱灯
https://mc.dfrobot.com.cn/thread-311174-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(3)---RGB律动灯
https://mc.dfrobot.com.cn/thread-311183-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(4)---WS2812条灯
https://mc.dfrobot.com.cn/thread-311190-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(5)---WS2812柱跳灯
https://mc.dfrobot.com.cn/thread-311192-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(6)---点阵频谱灯
https://mc.dfrobot.com.cn/thread-311201-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(7)---大方格频谱灯
https://mc.dfrobot.com.cn/thread-311364-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(8)---四位32段点阵屏
https://mc.dfrobot.com.cn/thread-311490-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(9)---X Music Spectrum
https://mc.dfrobot.com.cn/thread-311627-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(10)---WS2812硬板屏
https://mc.dfrobot.com.cn/thread-311641-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(11)---WS2812幻彩灯带
https://mc.dfrobot.com.cn/thread-313648-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(12)---米管快速节奏灯
https://mc.dfrobot.com.cn/thread-313708-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(13)---有机棒立柱灯
https://mc.dfrobot.com.cn/thread-313723-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(14)---水杯水瓶灯
https://mc.dfrobot.com.cn/thread-313803-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(15)--横排LED方管灯
https://mc.dfrobot.com.cn/thread-313811-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(16)--热干胶棒棒灯
https://mc.dfrobot.com.cn/thread-313844-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(17)--光导纤维灯
https://mc.dfrobot.com.cn/thread-313867-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(18)--LED平面板灯
https://mc.dfrobot.com.cn/thread-313951-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(19)--通体光纤灯
https://mc.dfrobot.com.cn/thread-313962-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(20)--首饰盒镜子灯
https://mc.dfrobot.com.cn/thread-313969-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(21)--CD 光盘灯
https://mc.dfrobot.com.cn/thread-313984-1-1.html
【花雕动手做】看见声音,基于Arduino系列音乐可视器(22)--LED无限魔方
https://mc.dfrobot.com.cn/thread-313994-1-1.html
【花雕动手做】有趣好玩的音乐可视化(23)--3合1闪点光纤
https://mc.dfrobot.com.cn/thread-314168-1-1.html
【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯
https://mc.dfrobot.com.cn/thread-314180-1-1.html
【花雕动手做】有趣好玩音乐可视化(25)--水龙卷旋涡灯
https://mc.dfrobot.com.cn/thread-314231-1-1.html
【花雕动手做】有趣好玩音乐可视化系列(26)--LED 超立方体
https://mc.dfrobot.com.cn/thread-314244-1-1.html
【花雕动手做】有趣好玩的音乐可视化(27)--磁搅LED水旋灯
https://mc.dfrobot.com.cn/thread-314273-1-1.html
【花雕动手做】有趣好玩的音乐可视化系列项目(28)--LED乒乓球灯
https://mc.dfrobot.com.cn/thread-314321-1-1.html
【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
https://mc.dfrobot.com.cn/thread-314474-1-1.html
【花雕动手做】有趣好玩的音乐可视化(30)--P6 LED单元板
https://mc.dfrobot.com.cn/thread-314540-1-1.html


实验一百五十八:QMC5883L电子指南针罗盘模块 三轴磁场传感器GY-271
https://mc.dfrobot.com.cn/thread-308195-1-1.html
实验一百六十三:BMI160 6轴惯性运动传感器 16位3轴加速度+超低功耗3轴陀螺仪  I2C/SPI 14LGA
https://mc.dfrobot.com.cn/thread-310371-1-1.html
实验一百六十五:2.4 英寸 TFT LCD 触摸屏模块 XPT2046 PCB ILI9341 240x320 像素 8 位 SPI 串口显示器 300mA
https://mc.dfrobot.com.cn/thread-309803-1-1.html
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
https://mc.dfrobot.com.cn/thread-309845-1-1.html
实验一百七十九:0.66英寸OLED显示模块 液晶屏模块IIC/I2C接口 64*48像素 SSD1306驱动芯片
https://mc.dfrobot.com.cn/thread-311179-1-1.html
实验一百八十一:1.3寸OLED液晶屏  I2C IIC通信 4针模块 1106/1306驱动 128*64像素
https://mc.dfrobot.com.cn/thread-311123-1-1.html
实验一百八十三:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议
https://mc.dfrobot.com.cn/thread-310273-1-1.html
实验一百八十五:MAX4466声音传感器 驻极体话筒放大器 麦克风可调功放模块 microphone
https://mc.dfrobot.com.cn/thread-310193-1-1.html
实验一百八十九:TDA1308 硅麦克风 数字咪头放大模块 拾音器放大板 楼氏SUNLEPHANT
https://mc.dfrobot.com.cn/thread-310246-1-1.html
实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
https://mc.dfrobot.com.cn/thread-310209-1-1.html
实验二百:RCWL-0515微波雷达感应开关 人体感应 智能感应探测传感器 12-15米远距离2.7G微波检测模块
https://mc.dfrobot.com.cn/thread-310313-1-1.html
实验二百零一:OPT101模拟光照传感器 TEMT6000光强度模块 单片光电二极管 YourCee
https://mc.dfrobot.com.cn/thread-311164-1-1.html
实验二百零三:Air724UG合宙 Cat14G模块 DTU物联网UART串口通信数据TCP透传 核心板组合套餐
https://mc.dfrobot.com.cn/thread-310342-1-1.html
实验二百零七:I2C红色8*8LED点阵模块ht16k33驱动1088BS树莓派物联网可扩展编程
https://mc.dfrobot.com.cn/thread-310951-1-1.html
实验二百零九:Gravity: I2C & UART BC20 NB-IoT & GNSS通信模块 NB-IoT广域低功耗无线通信 GPS/北斗精准定位
https://mc.dfrobot.com.cn/thread-310433-1-1.html
实验二百十一:LED 圆环内置IC全彩点控1-8-12-16-24-32 WS2812B 93灯 环形 圆盘
https://mc.dfrobot.com.cn/thread-314225-1-1.html
实验二百一十四:WS2812B全彩RGB像素屏 8x32点阵LED显示屏 可编程硬屏模块
https://mc.dfrobot.com.cn/thread-314378-1-1.html
实验二百一十七:2.9寸epd电子纸屏模块 spi电纸屏  黑白红三色eink墨水屏QYEG0290BNS800F6
https://mc.dfrobot.com.cn/thread-311306-1-1.html#pid498640
实验二百一十八:1.3寸 TFT显示屏 ST7735S驱动高清ips 模块
https://mc.dfrobot.com.cn/thread-313540-1-1.html#pid518278
实验二百二十:P6全彩LED模组 16X32显示屏单元板 P6-RGB-16X32-8S室内全彩8扫电子屏(HX-P6-16X32-A)
https://mc.dfrobot.com.cn/thread-314576-1-1.html

【花雕测评】【AI】尝试搭建Maixduino几种开发环境
https://makelog.dfrobot.com.cn/article-311383.html
【花雕测评】【AI】MaixPy基本使用、显示文字及摄像机的22个小项目
https://makelog.dfrobot.com.cn/article-311389.html
【花雕测评】【AI】Mind+图片文字显示、呼吸灯和网络应用的22项小实验
https://makelog.dfrobot.com.cn/article-311386.html
【花雕测评】【AI】MaixPy机器视觉与Color识别的8个尝试
https://makelog.dfrobot.com.cn/article-311393.html
【花雕测评】【AI】Mind+机器视觉之数字图像处理和显示的22种小测试
https://makelog.dfrobot.com.cn/article-311405.html
【花雕测评】【AI】MaixPy之神经网络KPU与人脸识别的初步体验
https://makelog.dfrobot.com.cn/article-311400.html
【花雕测评】【AI】Mind+机器视觉之颜色、维码与形状识别的8个小实验
https://makelog.dfrobot.com.cn/article-311417.html

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 16:07:34

背面

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 16:11:54

拼装成16X16的像素WS2812灯

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 18:11:03

WS2812B
是一个集控制电路与发光电路于一体的智能外控LED光源。其外型与一个5050LED灯珠相同,每个元件即为一个像素点。像素点内部包含了智能数字接口数据锁存信号整形放大驱动电路,还包含有高精度的内部振荡器和12V高压可编程定电流控制部分,有效保证了像素点光的颜色高度一致。

数据协议采用单线归零码的通讯方式,像素点在上电复位以后,DIN端接受从控制器传输过来的数据,首先送过来的24bit数据被第一个像素点提取后,送到像素点内部的数据锁存器,剩余的数据经过内部整形处理电路整形放大后通过DO端口开始转发输出给下一个级联的像素点,每经过一个像素点的传输,信号减少24bit。像素点采用自动整形转发技术,使得该像素点的级联个数不受信号传送的限制,仅仅受限信号传输速度要求。

LED具有低电压驱动,环保节能,亮度高,散射角度大,一致性好,超低功率,超长寿命等优点。将控制电路集成于LED上面,电路变得更加简单,体积小,安装更加简便。


【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 18:16:08

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 18:20:35

模块电原理图
【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 19:55:18

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图2

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图3
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 20:13:27

  【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  项目之一:WS2812FX库最简单的点亮形式

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  3.   项目之一:WS2812FX库最简单的点亮形式
  4. */
  5. #include <WS2812FX.h> //导入库
  6. #define LED_COUNT 256 //WS2812B LED数量
  7. #define LED_PIN    6 //WS2812B LED接脚
  8. WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  9. void setup() {
  10.   ws2812fx.init(); //初始化
  11.   ws2812fx.setBrightness(35); //设置亮度(0-255),可以控制总电流(重要!)
  12.   ws2812fx.setSpeed(100); // 设置速度
  13.   ws2812fx.setMode(FX_MODE_FIREWORKS_RANDOM);// 设置模式(内置63种模式)
  14.   ws2812fx.start(); //启动
  15. }
  16. void loop() {
  17.   ws2812fx.service(); //循环运行
  18. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 20:19:39

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-25 20:25:27

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 10:34:38

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 10:53:31

  【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  项目之三:应用Adafruit_NeoPixel库的入门极简程序

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  3.   项目之三:应用Adafruit_NeoPixel库的入门极简程序
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #define PIN        6 //接脚
  7. #define NUMPIXELS 256 //数量
  8. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  9. #define DELAYVAL 10 //延时
  10. void setup() {
  11.   pixels.setBrightness(22);//亮度
  12.   pixels.begin();//启动
  13. }
  14. void loop() {
  15.   pixels.clear();
  16.   for (int i = 0; i < NUMPIXELS; i++) {
  17.     pixels.setPixelColor(i, pixels.Color(50, 250, 0));//绿色
  18.     pixels.show();
  19.     delay(1);
  20.   }
  21. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 10:57:52

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 18:41:40

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 19:26:21

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 19:31:34

实验场景图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 21:54:42

  【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
   项目之五:多彩MegunoLink音乐节拍灯

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(29)--16X16硬屏灯
  3.   项目之五:多彩MegunoLink音乐节拍灯
  4. */
  5. #include<FastLED.h>
  6. #include<MegunoLink.h>
  7. #include<Filter.h>
  8. #define N_PIXELS  23
  9. #define MIC_PIN   A0
  10. #define LED_PIN   6
  11. #define NOISE 10
  12. #define TOP   (N_PIXELS+2)
  13. #define LED_TYPE  WS2811
  14. #define BRIGHTNESS  10
  15. #define COLOR_ORDER GRB
  16. CRGB leds[N_PIXELS];
  17. int lvl = 0, minLvl = 0, maxLvl = 10;
  18. ExponentialFilter<long> ADCFilter(5, 0);
  19. void setup() {
  20.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, N_PIXELS).setCorrection(TypicalLEDStrip);
  21.   FastLED.setBrightness(BRIGHTNESS);
  22. }
  23. void loop() {
  24.   int n, height;
  25.   n = analogRead(MIC_PIN);
  26.   n = abs(1023 - n);
  27.   n = (n <= NOISE) ? 0 : abs(n - NOISE);
  28.   ADCFilter.Filter(n);
  29.   lvl = ADCFilter.Current();
  30.   //  Serial.print(n);
  31.   //  Serial.print(" ");
  32.   //  Serial.println(lvl);
  33.   height = TOP * (lvl - minLvl) / (long)(maxLvl - minLvl);
  34.   if (height < 0L) height = 0;
  35.   else if (height > TOP) height = TOP;
  36.   for (uint8_t i = 0; i < N_PIXELS; i++) {
  37.     if (i >= height) leds[i] = CRGB(0, 0, 0);
  38.     else leds[i] = Wheel( map( i, 0, N_PIXELS - 1, 30, 150 ) );
  39.   }
  40.   FastLED.show();
  41. }
  42. CRGB Wheel(byte WheelPos) {
  43.   if (WheelPos < 85)
  44.     return CRGB(WheelPos * 3, 255 - WheelPos * 3, 0);
  45.   else if (WheelPos < 170) {
  46.     WheelPos -= 85;
  47.     return CRGB(255 - WheelPos * 3, 0, WheelPos * 3);
  48.   } else {
  49.     WheelPos -= 170;
  50.     return CRGB(0, WheelPos * 3, 255 - WheelPos * 3);
  51.   }
  52. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 21:57:37

实验场景图  动态图

【花雕动手做】看见声音,基于Arduino系列音乐可视器(29)图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-26 22:03:07

实验的视频记录
优酷:
B站:https://www.bilibili.com/video/B ... 87403d97f8d3cc0b7e5



回复

使用道具 举报

123下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail