5393浏览
楼主: 驴友花雕

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

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2022-9-17 20:44:51

实验场景图

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-17 21:11:26

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-17 21:13:32

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

  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  3.   项目程序之三:FastLED音乐反应节奏灯
  4.   模块接线:WS2812B接D6
  5.   MAX4466      UNO
  6.   VCC          5V
  7.   GND         GND
  8.   OUT          D7
  9. */
  10. #include<FastLED.h>
  11. #define LED_PIN 6
  12. #define NUM_LEDS 24
  13. CRGB leds[NUM_LEDS];
  14. uint8_t hue = 0;
  15. int soundsensor = A0;
  16. void setup() {
  17.   delay(3000);
  18.   FastLED.setBrightness(255);
  19.   pinMode(soundsensor, INPUT);
  20.   FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  21. }
  22. void loop() {
  23.   int sensval = digitalRead(soundsensor);
  24.   if (sensval == 1) {
  25.     leds[0] = CRGB :: Red;
  26.     fill_solid(leds, NUM_LEDS, CRGB :: Blue);
  27.     rainbow_moving();
  28.     FastLED.show();
  29.     delay(100);
  30.   }
  31.   else {
  32.     leds[0] = CRGB :: Black;
  33.     fill_solid(leds, NUM_LEDS, CRGB :: Black);
  34.     FastLED.show();
  35.     delay(100);
  36.   }
  37. }
  38. void rainbow_moving() {
  39.   for (int i = 0; i < NUM_LEDS; i++) {
  40.     leds[i] = CHSV(hue + (i * 10), 255, 255);
  41.   }
  42.   EVERY_N_MILLISECONDS(10) {
  43.     hue++;
  44.   }
  45. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-17 21:19:48

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 11:46:24

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


  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列小项目(23)--3合1闪点光纤灯
  3.   项目程序之四:NeoPixel 测试程序
  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 24
  14. // Declare our NeoPixel strip object:
  15. Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
  16. // Argument 1 = Number of pixels in NeoPixel strip
  17. // Argument 2 = Arduino pin number (most are valid)
  18. // Argument 3 = Pixel type flags, add together as needed:
  19. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  20. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  21. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  22. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  23. //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
  24. // setup() function -- runs once at startup --------------------------------
  25. void setup() {
  26.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  27.   // Any other board, you can remove this part (but no harm leaving it):
  28. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  29.   clock_prescale_set(clock_div_1);
  30. #endif
  31.   // END of Trinket-specific code.
  32.   strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  33.   strip.show();            // Turn OFF all pixels ASAP
  34.   strip.setBrightness(250); // Set BRIGHTNESS to about 1/5 (max = 255)
  35. }
  36. // loop() function -- runs repeatedly as long as board is on ---------------
  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.   // Do a theater marquee effect in various colors...
  43.   theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
  44.   theaterChase(strip.Color(127,   0,   0), 50); // Red, half brightness
  45.   theaterChase(strip.Color(  0,   0, 127), 50); // Blue, half brightness
  46.   rainbow(10);             // Flowing rainbow cycle along the whole strip
  47.   theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
  48. }
  49. // Some functions of our own for creating animated effects -----------------
  50. // Fill strip pixels one after another with a color. Strip is NOT cleared
  51. // first; anything there will be covered pixel by pixel. Pass in color
  52. // (as a single 'packed' 32-bit value, which you can get by calling
  53. // strip.Color(red, green, blue) as shown in the loop() function above),
  54. // and a delay time (in milliseconds) between pixels.
  55. void colorWipe(uint32_t color, int wait) {
  56.   for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  57.     strip.setPixelColor(i, color);         //  Set pixel's color (in RAM)
  58.     strip.show();                          //  Update strip to match
  59.     delay(wait);                           //  Pause for a moment
  60.   }
  61. }
  62. // Theater-marquee-style chasing lights. Pass in a color (32-bit value,
  63. // a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
  64. // between frames.
  65. void theaterChase(uint32_t color, int wait) {
  66.   for (int a = 0; a < 10; a++) { // Repeat 10 times...
  67.     for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
  68.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  69.       // 'c' counts up from 'b' to end of strip in steps of 3...
  70.       for (int c = b; c < strip.numPixels(); c += 3) {
  71.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  72.       }
  73.       strip.show(); // Update strip with new contents
  74.       delay(wait);  // Pause for a moment
  75.     }
  76.   }
  77. }
  78. // Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
  79. void rainbow(int wait) {
  80.   // Hue of first pixel runs 5 complete loops through the color wheel.
  81.   // Color wheel has a range of 65536 but it's OK if we roll over, so
  82.   // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  83.   // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  84.   for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
  85.     for (int i = 0; i < strip.numPixels(); i++) { // For each pixel in strip...
  86.       // Offset pixel hue by an amount to make one full revolution of the
  87.       // color wheel (range of 65536) along the length of the strip
  88.       // (strip.numPixels() steps):
  89.       int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
  90.       // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
  91.       // optionally add saturation and value (brightness) (each 0 to 255).
  92.       // Here we're using just the single-argument hue variant. The result
  93.       // is passed through strip.gamma32() to provide 'truer' colors
  94.       // before assigning to each pixel:
  95.       strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
  96.     }
  97.     strip.show(); // Update strip with new contents
  98.     delay(wait);  // Pause for a moment
  99.   }
  100. }
  101. // Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
  102. void theaterChaseRainbow(int wait) {
  103.   int firstPixelHue = 0;     // First pixel starts at red (hue 0)
  104.   for (int a = 0; a < 30; a++) { // Repeat 30 times...
  105.     for (int b = 0; b < 3; b++) { //  'b' counts from 0 to 2...
  106.       strip.clear();         //   Set all pixels in RAM to 0 (off)
  107.       // 'c' counts up from 'b' to end of strip in increments of 3...
  108.       for (int c = b; c < strip.numPixels(); c += 3) {
  109.         // hue of pixel 'c' is offset by an amount to make one full
  110.         // revolution of the color wheel (range 65536) along the length
  111.         // of the strip (strip.numPixels() steps):
  112.         int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
  113.         uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
  114.         strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
  115.       }
  116.       strip.show();                // Update strip with new contents
  117.       delay(wait);                 // Pause for a moment
  118.       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  119.     }
  120.   }
  121. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 12:52:26

实验场景图  动态图

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 13:00:19

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 15:19:49

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


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




回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 16:07:52

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

https://v.youku.com/v_show/id_XN ... hcb.playlsit.page.1



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-18 16:09:31

实验场景图

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

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-10-5 10:15:35

【花雕动手做】看见声音,基于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


回复

使用道具 举报

12
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

硬件清单

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

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

mail