5626浏览
楼主: 驴友花雕

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2022-9-19 20:18:20

  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之一:点亮ws2812灯带LED


  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  3.   项目程序之一:点亮ws2812灯带LED
  4. */
  5. #include <Adafruit_NeoPixel.h>
  6. #define PIN 6
  7. #define MAX_LED 62
  8. #define ADD true
  9. #define SUB false
  10. int val = 0;
  11. boolean stat = ADD;
  12. Adafruit_NeoPixel strip = Adafruit_NeoPixel( MAX_LED, PIN, NEO_RGB + NEO_KHZ800 );
  13. void setup()
  14. {
  15.   strip.begin();           
  16.   strip.show();           
  17. }
  18. void loop()
  19. {
  20.   uint8_t i,a=0;                                       
  21.   uint32_t color = strip.Color(255, 0, 0);         
  22.   while(a<63)
  23.   {
  24.       for(i=0;i<62;i++)
  25.       {
  26.         if(i==a) strip.setPixelColor(i, color);     
  27.         else strip.setPixelColor(i, 0);            
  28.       }
  29.        strip.show();                                
  30.        delay(3);                                   
  31.        a++;                                         
  32.   }
  33. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-19 20:20:58

实验场景图  动态图

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-19 21:16:41

  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之二:NeoPixel Ring 绿色灯


  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  3.   项目程序之二:NeoPixel Ring 绿色灯
  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. #define PIN        6 // On Trinket or Gemma, suggest changing this to 1
  11. // How many NeoPixels are attached to the Arduino?
  12. #define NUMPIXELS 62 // Popular NeoPixel ring size
  13. // When setting up the NeoPixel library, we tell it how many pixels,
  14. // and which pin to use to send signals. Note that for older NeoPixel
  15. // strips you might need to change the third parameter -- see the
  16. // strandtest example for more information on possible values.
  17. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  18. #define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
  19. void setup() {
  20.   // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  21.   // Any other board, you can remove this part (but no harm leaving it):
  22. #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  23.   clock_prescale_set(clock_div_1);
  24. #endif
  25.   // END of Trinket-specific code.
  26.   pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  27. }
  28. void loop() {
  29.   pixels.clear(); // Set all pixel colors to 'off'
  30.   // The first NeoPixel in a strand is #0, second is 1, all the way up
  31.   // to the count of pixels minus one.
  32.   for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
  33.     // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
  34.     // Here we're using a moderately bright green color:
  35.     pixels.setPixelColor(i, pixels.Color(250, 250, 250));
  36.     pixels.show();   // Send the updated pixel colors to the hardware.
  37.     delay(6); // Pause before next pass through loop
  38.   }
  39. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-19 21:18:09

实验场景图

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-19 21:22:44

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-20 15:03:58

  【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  项目程序之三:NeoPixel 环形灯条测试程序


  1. /*
  2.   【花雕动手做】有趣好玩的音乐可视化系列项目(24)--无限LED镜子灯
  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 62
  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), 250); // Red
  40.   colorWipe(strip.Color(  0, 255,   0), 250); // Green
  41.   colorWipe(strip.Color(  0,   0, 255), 250); // Blue
  42.   // Do a theater marquee effect in various colors...
  43.   theaterChase(strip.Color(127, 127, 127), 250); // White, half brightness
  44.   theaterChase(strip.Color(127,   0,   0), 250); // Red, half brightness
  45.   theaterChase(strip.Color(  0,   0, 127), 250); // 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(30);                           //  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 < 20; 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(30);  // 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 < 2 * 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(2);  // 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(50);                 // Pause for a moment
  118.       firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
  119.     }
  120.   }
  121. }
复制代码



回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-20 16:11:18

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-20 16:13:05

实验场景图

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 06:55:08

找到一张无限镜子的原理图,多次反射的效果

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 07:16:49

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 10:10:09

拆开吊顶平板灯开始改造
【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 10:16:16

底面装个有机软镜子

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

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

找到一种小规格的装修角条

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 10:25:34

制成灯带底座

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 10:29:11

玻璃贴膜改为银灰色,透光效果好一些

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 10:34:20

贴膜后简单的镜子,有点像了

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 15:11:55

安装灯带

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 15:15:28

实验场景图

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 15:19:36

实验场景图  动态图

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2022-9-21 15:43:55

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

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

一个小规格的相框

【花雕动手做】有趣好玩的音乐可视化(24)--无限LED镜子灯图1

回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail