12浏览
查看: 12|回复: 2

[项目] 【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表

[复制链接]
在这里,我向您介绍一款由 Arduino 供电的立体声 VU 表,具有模式、颜色、亮度和音频灵敏度控制选项。完整的 Arduino 代码链接如下。您可以花 2 美元为本机添加蓝牙音频连接功能(指南 -   • DIY 蓝牙 RGB VU 表 |多色色灯).此外,您可以将此装置制作成一个令人惊叹的角灯(指南 -  • DIY 音乐反应式 LED 落地灯 |Arduin...).享受!。

如果您觉得此视频很有趣,我恳请您通过点赞和订阅来表达您的支持。您的参与不仅推动了频道的发展,而且为我创作更多引人入胜的内容提供了巨大的动力。衷心感谢您的宝贵支持!  
/ 哈兹科技DIY 音频频谱分析仪 1602 LCD 显示屏 -  • DIY 音频频谱分析仪 LCD 显示屏 |...32 频段 LED 音频频谱分析仪 |Arduino Nano + MAX 7219 -  • 32 频段 LED 音频频谱分析仪 |阿尔杜... “Stereo_Multi_Function_VU_Meter” Arduino 代码、“Adafruit_NeoPixel-master” 库和接线图链接 https://github.com/HAZI-TECH/Arduino-...
特别感谢 “ericBcreator”,他是这个项目的原始创作者。

零件清单
Arduino Nano x 1
1K 欧姆电位器 x 2
瞬时按钮 x 2
拨动开关 x 2
WS2812B LED灯带 x 60LED单灯带 / 60LED双灯带
10K 欧姆电阻器 x 5
330 欧姆电阻器 x 2
1uF 电容器 x 1
3.5mm 立体声母插孔 x 2
DC 母插孔 x 1
3 针 JST 连接器 x 2
塑料盒 x 1
1 英寸电线外壳 x 2 英尺
5V 2A 电源 x 1


【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图1

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图2

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图4


【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图3

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图6

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图5

驴友花雕  中级技神
 楼主|

发表于 6 小时前

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表

项目代码

  1. /*
  2. **********************************************************************
  3. * Stereo VU Meter for 1 or 2 LED rings or strips build by ericBcreator
  4. * Designed to be used with an Arduino UNO, Nano or compatible device.
  5. **********************************************************************
  6. * Notice: search for @EB in the Sketch for important variables to set
  7. * for the Sketch to work with your setup.
  8. **********************************************************************
  9. * Last updated 20180202 by ericBcreator
  10. *
  11. * This code is free for personal use, not for commercial purposes.
  12. * Please leave this header intact.
  13. *
  14. * contact: ericBcreator@gmail.com
  15. **********************************************************************
  16. */
  17. #include <Adafruit_NeoPixel.h>
  18. #define nonLinearLogAudio
  19. //#define led_strip_60                                    //uncomment this if you are using a single 60 LED strip (Center to sides mode)
  20. #define led_2_strip_60                                  //uncomment this if you are using two 60 LED strips (Left-Right bottom to top mode)
  21. //#define led_strip_30                                    //uncomment this if you are using a single 30 LED strip
  22. //#define led_2_strip_30                                  //uncomment this if you are using two 30 LED strips
  23. //#define led_strip_144                                   //uncomment this if you are using a single 144 LED strip
  24. //#define led_2_strip_144                                 //uncomment this if you are using two 144 LED strips
  25. const int useSensorValues = true;                         // @EB
  26. //
  27. // setup pins
  28. //
  29. int leftPin = A0, rightPin = A1;                          // left audio in on analog 0, right on analog 1
  30. int brightnessPin = A4, sensitivityPin = A5;              // potentiometers for brightness and sensitivity on analog 4 and 5
  31. int leftStripPin = 5;                                     // DIN of left led strip on digital pin 5
  32. int rightStripPin = 6;                                    // DIN of right led strip on digital pin 6
  33. int showPeaksPin = 7;                                     // switch to toggle peaks on or off on digital pin 7 (7, 9 for box version)
  34. int showPeaksMomentarySwitch = false;                     // set false for an on/off toggle switch
  35. int reverseShowPeaks = true;                              // reverses the on/off setting in case you made a wiring mistake ;-) @EB
  36. int selectButton1Pin = 8;                                 // push button for changing settings on digital pin 8
  37. int useSelectButton1 = true;                              // set to false if no push button1 for selecting the color scheme is connected  @EB
  38. int selectButton2Pin = 9;                                 // push button for changing settings on digital pin 9
  39. int useSelectButton2 = true;                              // set to false if no push button2 is connected  @EB
  40. #if defined (led_strip_60)
  41.   //settings for a 60 led strip
  42.   int stripNumOfLeds = 60;                                  // the total number of leds
  43.   int stripsOn2Pins = false;                                // set to true if the LED strips or rings are connected to 2 input pins
  44.   uint32_t stripColor[31];                                  // half of the number of leds + 1
  45.   int displayMiddleLed = true;                              // display the middle led (blue). set to true for one strip, false for two strips or rings
  46.   int splitStrip = false;                                   // set to true when using 2 strips or rings, false for one strip
  47.   int middleOffset = 1;                                     // offset for the middle led when using one strip
  48.   int startupAnimationDelay = 6;                            // delay for the startup animation
  49.   int orangeLimitAmount = 0;                                // limit the amount of green of the middle LEDs to make them more orange
  50.   int swapLeftRight = false;                                // swap the left and right input values or not
  51.   
  52.   int dropDelay = 5;                                        // hold time before dropping the leds
  53.   float dropFactor = .94;                                   // value for dropping the leds
  54.   
  55.   int peakTimeNoDropDelay = 250;                            // peak hold time when not dropping the peaks (when droppingPeak is false)
  56.   int peakTimeFirstDropDelay = 70;                          // peak hold time when dropping the first peak
  57.   int peakTimeDropDelay = 7;                                // peak hold time when dropping the rest of the peaks
  58.   float peakDropFactor = .94;                               // value for dropping the peaks
  59.   int droppingPeakFade = false;                             // display the dropping peak fading to black or not
  60.   
  61.   int bouncingPeaksNumOfLeds = 6;                           // how many leds to bounce up (max)
  62.   int bouncingPeaksNumOfLedsMin = 3;                        // how many leds to bounce up (min) when using dynamicBouncingPeaks
  63.   int bouncingPeakDelay = 4;                                // delay between peak bounce updates
  64.   int bouncingPeakCounterInc = 10;                          // increase counter for each bounce update. note: it uses a 0-180 sin function for the bouncing
  65. #elif defined (led_2_strip_60)
  66.   //settings for 2 60 led strips
  67.   int stripNumOfLeds = 60;
  68.   int stripsOn2Pins = true;
  69.   uint32_t stripColor[61];
  70.   int displayMiddleLed = false;
  71.   int splitStrip = true;
  72.   int middleOffset = 0;
  73.   int startupAnimationDelay = 1;
  74.   int orangeLimitAmount = 0;
  75.   int swapLeftRight = false;
  76.   
  77.   int dropDelay = 5;
  78.   float dropFactor = .94;
  79.   
  80.   int peakTimeNoDropDelay = 250;
  81.   int peakTimeFirstDropDelay = 70;
  82.   int peakTimeDropDelay = 7;
  83.   float peakDropFactor = .94;
  84.   int droppingPeakFade = false;
  85.   
  86.   int bouncingPeaksNumOfLeds = 12;
  87.   int bouncingPeaksNumOfLedsMin = 4;
  88.   int bouncingPeakDelay = 4;
  89.   int bouncingPeakCounterInc = 10;
  90.   
  91. #elif defined (led_strip_30)
  92.   //settings for a 30 led strip
  93.   int stripNumOfLeds = 30;                                  // the total number of leds
  94.   int stripsOn2Pins = false;                                // set to true if the LED strips or rings are connected to 2 input pins
  95.   uint32_t stripColor[16];                                  // half of the number of leds + 1
  96.   int displayMiddleLed = true;                              // display the middle led (blue). set to true for one strip, false for two strips or rings
  97.   int splitStrip = false;                                   // set to true when using 2 strips or rings, false for one strip
  98.   int middleOffset = 1;                                     // offset for the middle led when using one strip
  99.   int startupAnimationDelay = 10;                           // delay for the startup animation
  100.   int orangeLimitAmount = 0;                                // limit the amount of green of the middle LEDs to make them more orange
  101.   int swapLeftRight = false;                                // swap the left and right input values or not
  102.   
  103.   int dropDelay = 10;                                       // hold time before dropping the leds
  104.   float dropFactor = .9;                                    // value for dropping the leds
  105.   
  106.   int peakTimeNoDropDelay = 250;                            // peak hold time when not dropping the peaks (set droppingPeak true or false)
  107.   int peakTimeFirstDropDelay = 150;                         // peak hold time when dropping the first peak
  108.   int peakTimeDropDelay = 15;                               // peak hold time when dropping the rest of the peaks
  109.   float peakDropFactor = .94;                               // value for dropping the peaks
  110.   int droppingPeakFade = false;                             // display the dropping peak fading to black or not
  111.   
  112.   int bouncingPeaksNumOfLeds = 4;                           // how many leds to bounce up (max)
  113.   int bouncingPeaksNumOfLedsMin = 2;                        // how many leds to bounce up (min) when using dynamicBouncingPeaks
  114.   int bouncingPeakDelay = 4;                                // delay between peak bounce updates
  115.   int bouncingPeakCounterInc = 9;                           // increase counter for each bounce update. note: it uses a 0-180 sin function for the bouncing
  116. #elif defined (led_2_strip_30)
  117.   //settings for 2 30 led strips
  118.   int stripNumOfLeds = 30;
  119.   int stripsOn2Pins = true;
  120.   uint32_t stripColor[31];
  121.   int displayMiddleLed = false;
  122.   int splitStrip = true;
  123.   int middleOffset = 0;
  124.   int startupAnimationDelay = 1;
  125.   int orangeLimitAmount = 0;
  126.   int swapLeftRight = false;
  127.   
  128.   int dropDelay = 5;
  129.   float dropFactor = .94;
  130.   
  131.   int peakTimeNoDropDelay = 250;
  132.   int peakTimeFirstDropDelay = 70;
  133.   int peakTimeDropDelay = 7;
  134.   float peakDropFactor = .94;
  135.   int droppingPeakFade = false;
  136.   
  137.   int bouncingPeaksNumOfLeds = 12;
  138.   int bouncingPeaksNumOfLedsMin = 4;
  139.   int bouncingPeakDelay = 4;
  140.   int bouncingPeakCounterInc = 10;
  141.   
  142. #elif defined (led_strip_144)
  143.   //settings for a 144 led strip
  144.   int stripNumOfLeds = 145;
  145.   int stripsOn2Pins = false;
  146.   uint32_t stripColor[73];
  147.   int displayMiddleLed = true;
  148.   int splitStrip = false;
  149.   int middleOffset = 1;
  150.   int startupAnimationDelay = 1;
  151.   int orangeLimitAmount = 0;
  152.   int swapLeftRight = false;
  153.   
  154.   int dropDelay = 4;
  155.   float dropFactor = .92;
  156.   
  157.   int peakTimeNoDropDelay = 250;
  158.   int peakTimeFirstDropDelay = 100;
  159.   int peakTimeDropDelay = 5;
  160.   float peakDropFactor = .94;
  161.   int droppingPeakFade = false;
  162.   
  163.   int bouncingPeaksNumOfLeds = 10;
  164.   int bouncingPeaksNumOfLedsMin = 4;
  165.   int bouncingPeakDelay = 2;
  166.   int bouncingPeakCounterInc = 10;
  167. #elif defined (led_2_strip_144)
  168.   //settings for 2 144 led strips
  169.   int stripNumOfLeds = 144;
  170.   int stripsOn2Pins = true;
  171.   uint32_t stripColor[145];
  172.   int displayMiddleLed = false;
  173.   int splitStrip = true;
  174.   int middleOffset = 0;
  175.   int startupAnimationDelay = 1;
  176.   int orangeLimitAmount = 0;
  177.   int swapLeftRight = false;
  178.   
  179.   int dropDelay = 5;
  180.   float dropFactor = .94;
  181.   
  182.   int peakTimeNoDropDelay = 250;
  183.   int peakTimeFirstDropDelay = 70;
  184.   int peakTimeDropDelay = 7;
  185.   float peakDropFactor = .94;
  186.   int droppingPeakFade = false;
  187.   
  188.   int bouncingPeaksNumOfLeds = 12;
  189.   int bouncingPeaksNumOfLedsMin = 4;
  190.   int bouncingPeakDelay = 4;
  191.   int bouncingPeakCounterInc = 10;
  192.   
  193. #endif
  194. //
  195. // setup other user variables
  196. //
  197. // basic settings
  198. int pulsing = false;                                       // pulsing will display from the middle of each strip or ring  @EB
  199. int spinCircle = false;                                    // spin the animation. will not work with stripsOn2Pins  @EB
  200. int animType = 0;                                         // startup animation selection (1 looks nice for 1 ring)  @EB
  201. int colorScheme = 10;                                     // 0: green-red, 1: blue-green, 2: blue-red, 3: red-blue, 4: green-blue, 5: red-green, 6: blue-white-red
  202.                                                           // 7: red-white-blue, 8: green-white-red, 9: green-white-blue, 10: color wheel, 11: spinning color wheel,
  203.                                             // 12: as 11 but spread with factor colorScheme12Factor  @EB
  204. int maxColorScheme = 12;                                  // used for looping through the color schemes with the switch button
  205. int colorScheme11SpinDelay = stripNumOfLeds / 4 ;         // delay for spinning scheme 11
  206. int colorScheme12Factor = 3;                              // wheel spread factor for scheme 12 @EB
  207. int minValue = 10;                                        // min analog input value
  208. int sensitivityValue = 110;                               // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true)
  209. #ifdef highLevelInput
  210.   int maxValue = 700;                                     // max analog input value (0-1023 equals 0-5V). try 300 for low level input, 700 for high
  211.   int maxSensitivity = 2 * 255;                           // set to a higher setting to amplify low input levels. try 4 * 255 for low level input, 2 * 255 for high
  212. #else
  213.   int maxValue = 300;                                     // max analog input value (0-1023 equals 0-5V). try 300 for low level input, 700 for high
  214.   int maxSensitivity = 4 * 255;                           // set to a higher setting to amplify low input levels. try 4 * 255 for low level input, 2 * 255 for high
  215. #endif
  216. int ledBrightness = 30;                                   // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true)
  217. int sensorDeviationBrightness = 3;                        // eliminate fluctuating values
  218. int overflowDelay = 10;                                   // overflow hold time
  219. // peak settings @EB
  220. int displayPeaks = false;                                 // value will be set by the switch if useSensorValues = true
  221. int displayTopAsPeak = true;                              // always display the top LED in peak color
  222. int droppingPeak = true;                                  // display dropping peaks or not. note: displayPeaks has to be true
  223. int bouncingPeaks = false;                                // display bouncing peaks or not. note: displayPeaks has to be true
  224. int dynamicBouncingPeaks = false;                         // bounce less with lower peaks. note: bouncingPeaks has to be true
  225. //
  226. // initialize other variables
  227. //
  228. int numOfSegments, halfNumOfSegments, stripMiddle, maxDisplaySegments;
  229. float sensitivityFactor;
  230. float nonLinearResponseFactor;
  231. int brightnessValue, prevBrightnessValue;
  232. float ledFactor, ledFactor_div_numOfSegments;
  233. uint32_t stripMiddleColor, stripOverflowColor, stripHoldColor;
  234. uint32_t colorValue;
  235. int leftValue = 0, rightValue = 0, maxReadValue = 0;
  236. int leftValueN = 0, rightValueN = 0;
  237. int leftAnalogValue = 0, rightAnalogValue = 0;
  238. float log10MaxDisplaySegments;
  239. int prevLeftValue = 0, prevRightValue = 0;
  240. int prevLeftAnalogValue = 0, prevRightAnalogValue = 0;
  241. int selectButton1PinState = 0, prevSelectButton1PinState = 0;
  242. int selectButton2PinState = 0, prevSelectButton2PinState = 0;
  243. int selectButton1PinSetting = colorScheme;
  244. int selectButton2PinSetting = 0;
  245. int i, j;
  246. int dropLeft, dropRight;
  247. int leftDropTime, rightDropTime;
  248. int leftPeak = 0, rightPeak = 0;
  249. int leftPeakTime = 0, rightPeakTime = 0;
  250. int leftFirstPeak = true, rightFirstPeak = true;
  251. int showPeaksPinSetting, prevShowPeaksPinSetting;
  252. int stripPulseMiddle = 0;
  253. int halfLeftValue, halfRightValue, halfPrevLeftValue, halfPrevRightValue;
  254. int leftPeakBouncing = false, rightPeakBouncing = false;
  255. int leftPeakBounce = 0, rightPeakBounce = 0;
  256. int prevLeftPeakBounce = 0, prevRightPeakBounce = 0;
  257. int leftPeakBounceCounter = 0, rightPeakBounceCounter = 0;
  258. int leftPeakBounceDelayCounter = 0, rightPeakBounceDelayCounter = 0;
  259. int leftBouncingPeaksNumOfLeds = 0, rightBouncingPeaksNumOfLeds = 0;
  260. float bounceFactor;
  261. int colorScheme11SpinValue = 0, colorScheme11SpinDelayValue = 0;
  262. int colorSchemeFactor = 1;
  263. long selectButton1Timer;
  264. int spinDelayCounter = 0, spinCounter = 0, spinTurnsCounter = 0, spinTurnsMax = 0, spinTurnsDelay = 0, spinTurnsDelayMax = 0;
  265. int spinCounterInc = 1;
  266. int spinDelay = 0;
  267. //
  268. // initialize the strip or rings
  269. //
  270. Adafruit_NeoPixel left_strip = Adafruit_NeoPixel(stripNumOfLeds, leftStripPin, NEO_GRB + NEO_KHZ800);
  271. Adafruit_NeoPixel right_strip = Adafruit_NeoPixel(stripNumOfLeds, rightStripPin, NEO_GRB + NEO_KHZ800);
  272. //
  273. // setup
  274. //
  275. void setup() {
  276.   #ifdef DEBUG
  277.     Serial.begin(9600);
  278.   #endif
  279.   randomSeed(analogRead(2));
  280.   if (stripsOn2Pins) {
  281.     numOfSegments = stripNumOfLeds;
  282.     maxDisplaySegments = numOfSegments - 1;
  283.    
  284.     stripMiddle = stripNumOfLeds;
  285.     stripPulseMiddle = stripMiddle / 2;
  286.     spinCircle = false;
  287.   }
  288.   else {
  289.     numOfSegments = stripNumOfLeds / 2;
  290.     stripMiddle = stripNumOfLeds / 2;
  291.     maxDisplaySegments = stripMiddle - 1;
  292.     stripPulseMiddle = stripMiddle / 2;
  293.   }
  294.   halfNumOfSegments = numOfSegments / 2;
  295.   bounceFactor = (float) bouncingPeaksNumOfLeds / (maxDisplaySegments - bouncingPeaksNumOfLeds);
  296.   nonLinearResponseFactor = 90 / (float) maxDisplaySegments;
  297.   log10MaxDisplaySegments = log10(maxDisplaySegments);
  298.   pinMode(showPeaksPin, INPUT);   
  299.   
  300.   if (useSelectButton1)
  301.     pinMode(selectButton1Pin, INPUT);  
  302.   left_strip.begin();
  303.   if (stripsOn2Pins)
  304.     right_strip.begin();
  305.   if (useSensorValues) {
  306.     readSensorValues();
  307.     setInitialDisplayPeaks();
  308.   }
  309.   else {
  310.     setStripColors();
  311.     setSensitivityFactor();
  312.   }
  313.   #ifdef DEBUG_TEST_LEDS
  314.     displayTest();
  315.   #endif
  316.   startupAnimation();
  317. }
  318. //
  319. // main loop
  320. //
  321. void loop() {
  322.   #ifdef DEBUG_PRINT_LOOP_TIME
  323.     long time = millis();
  324.   #endif
  325.   if (useSensorValues)
  326.     readSensorValues();
  327.   
  328.   readValues();
  329.   #if defined (DEBUG_NO_PEAKS)
  330.     displayPeaks = false;
  331.   #endif
  332.   #if defined (DEBUG_PEAKS)
  333.     displayPeaks = true;
  334.   #endif
  335.   if (pulsing) {
  336.     drawPulsingValues();
  337.   }
  338.   else {
  339.     drawValues();
  340.     if (displayPeaks) {
  341.       getPeaks();
  342.       drawPeaks();
  343.     }
  344.   }
  345.   left_strip.show();
  346.   if (stripsOn2Pins)
  347.     right_strip.show();
  348.    
  349.   storePrevValues();
  350.   checkSpinCircle();
  351.   #ifdef DEBUG_PRINT_LOOP_TIME
  352.     time = millis() - time;
  353.     Serial.println(time);
  354.   #endif
  355. }
  356. //
  357. // functions
  358. //
  359. void setInitialDisplayPeaks() {
  360.   #if !defined (DEBUG_NO_PEAK_SWITCH)
  361.     showPeaksPinSetting = digitalRead(showPeaksPin);
  362.   
  363.     if (showPeaksPinSetting == HIGH)
  364.       displayPeaks = false;
  365.   #endif
  366.   if (reverseShowPeaks) {
  367.     if (!displayPeaks)
  368.       displayPeaks = true;
  369.     else
  370.       displayPeaks = false;
  371.   }
  372.   
  373.   prevShowPeaksPinSetting = showPeaksPinSetting;
  374. }
  375. void readSensorValues() {
  376.   //
  377.   // peaks pin
  378.   //
  379.   #if !defined (DEBUG_NO_PEAK_SWITCH)
  380.     showPeaksPinSetting = digitalRead(showPeaksPin);
  381.   
  382.     if (showPeaksMomentarySwitch) {
  383.       if (showPeaksPinSetting == LOW && prevShowPeaksPinSetting == HIGH) {
  384.         if (displayPeaks == true) {
  385.           displayPeaks = false;
  386.           clearLeftPeak();
  387.           clearRightPeak();        
  388.           if (showPeaksMomentarySwitch)
  389.             while (digitalRead(showPeaksPin) == LOW) {}
  390.         }
  391.         else {
  392.           displayPeaks = true;
  393.         }
  394.       }
  395.     }
  396.     else {
  397.       if (reverseShowPeaks) {
  398.         if (showPeaksPinSetting == HIGH && prevShowPeaksPinSetting == LOW)
  399.           displayPeaks = true;
  400.         else if (showPeaksPinSetting == LOW && prevShowPeaksPinSetting == HIGH) {
  401.           displayPeaks = false;
  402.           clearLeftPeak();
  403.           clearRightPeak();        
  404.         }
  405.       }
  406.       else {   
  407.         if (showPeaksPinSetting == LOW && prevShowPeaksPinSetting == HIGH)
  408.           displayPeaks = true;
  409.         else if (showPeaksPinSetting == HIGH && prevShowPeaksPinSetting == LOW) {
  410.           displayPeaks = false;
  411.           clearLeftPeak();
  412.           clearRightPeak();        
  413.         }
  414.       }
  415.     }
  416.     if (pulsing) {
  417.       if (displayPeaks)
  418.         displayTopAsPeak = true;
  419.       else
  420.         displayTopAsPeak = false;
  421.     }
  422.     prevShowPeaksPinSetting = showPeaksPinSetting;
  423.   #endif
  424.   
  425.   //
  426.   // selectButtonPin 1 and 2
  427.   //
  428.   if (useSelectButton1) {      
  429.     selectButton1PinState = digitalRead(selectButton1Pin);
  430.    
  431.     if (selectButton1PinState == HIGH && prevSelectButton1PinState == LOW)
  432.       selectButton1Timer = millis();
  433.       
  434.     if (selectButton1PinState == HIGH && prevSelectButton1PinState == HIGH) {
  435.       if ((millis() - selectButton1Timer) > 1000) {
  436.         pulsing = !pulsing;
  437.         setStripColors();
  438.         displayNumber(colorScheme, 250);
  439.         while (digitalRead(selectButton1Pin) == HIGH) {}
  440.         selectButton1PinState = LOW;
  441.         clearValues();
  442.       }
  443.     }
  444.     else if (selectButton1PinState == LOW && prevSelectButton1PinState == HIGH) {
  445.       selectButton1PinSetting++;
  446.       if (selectButton1PinSetting > maxColorScheme) {
  447.         selectButton1PinSetting = 0;
  448.       }
  449.       colorScheme = selectButton1PinSetting;
  450.       if (colorScheme == 12)
  451.         colorScheme11SpinValue = (colorScheme11SpinValue * colorScheme12Factor);
  452.       setStripColors();
  453.       displayNumber(colorScheme, 250);
  454.     }
  455.     prevSelectButton1PinState = selectButton1PinState;
  456.   }
  457.   if (useSelectButton2) {
  458.     selectButton2PinState = digitalRead(selectButton2Pin);
  459.    
  460.     if (selectButton2PinState == HIGH && prevSelectButton2PinState == LOW) {
  461.       selectButton2PinSetting++;
  462.       
  463.       switch(selectButton2PinSetting) {
  464.         case 0:
  465.         case 1: {   
  466.           pulsing = true;
  467.           spinCircle = false;
  468.           break;
  469.         }
  470.         case 2: {
  471.           pulsing = true;
  472.           spinCircle = true;
  473.           break;
  474.         }
  475.         case 3: {
  476.           pulsing = false;
  477.           spinCircle = false;
  478.           selectButton2PinSetting = 0;
  479.           break;
  480.         }
  481.       }
  482.       
  483.       setStripColors();
  484.       displayNumber(colorScheme, 250);
  485.     }
  486.    
  487.     prevSelectButton2PinState = selectButton2PinState;
  488.   }
  489.   
  490.   //
  491.   // brightness
  492.   //
  493.   brightnessValue = analogRead(brightnessPin);
  494.   brightnessValue = map(brightnessValue, 0, 1023, 0, 255);
  495.   
  496.   if (abs(brightnessValue - prevBrightnessValue) > sensorDeviationBrightness) {
  497.     ledBrightness = brightnessValue;
  498.     setStripColors();
  499.     prevBrightnessValue = brightnessValue;
  500.   }
  501.   //
  502.   // colorscheme 11 spinning wheel
  503.   //
  504.   if (colorScheme == 11 || colorScheme == 12) {
  505.     colorScheme11SpinDelayValue++;
  506.     if (colorScheme11SpinDelayValue == colorScheme11SpinDelay) {
  507.       colorScheme11SpinDelayValue = 0;
  508.       colorScheme11SpinValue++;
  509.       if (colorScheme11SpinValue > maxDisplaySegments * colorSchemeFactor)
  510.         colorScheme11SpinValue = 0;
  511.       setStripColors();
  512.     }
  513.   }
  514.   //
  515.   // sensitivity
  516.   //
  517.   sensitivityValue = analogRead(sensitivityPin);
  518.   sensitivityValue = map(sensitivityValue, 0, 1023, 0, 255);
  519.   setSensitivityFactor();
  520. }
  521. void setSensitivityFactor() {
  522.   //sensitivityValue_div_numOfSegments = sensitivityValue / numOfSegments;
  523.   sensitivityFactor = ((float) sensitivityValue / 255 * (float) maxSensitivity / 255);
  524. }
  525. void readValues() {
  526.   #ifdef averageReadings
  527.     leftAnalogValue = 0;
  528.     rightAnalogValue = 0;
  529.    
  530.     for (i = 0; i <= averageNumOfReadings; i++) {
  531.       leftAnalogValue += analogRead(leftPin);
  532.       rightAnalogValue += analogRead(rightPin);
  533.     }
  534.     leftAnalogValue /= averageNumOfReadings;
  535.     rightAnalogValue /= averageNumOfReadings;
  536.    
  537.   #else  
  538.     leftAnalogValue = analogRead(leftPin);
  539.     rightAnalogValue = analogRead(rightPin);
  540.   #endif
  541.   if (swapLeftRight) {
  542.     int tempValue = leftAnalogValue;
  543.     leftAnalogValue = rightAnalogValue;
  544.     rightAnalogValue = tempValue;
  545.   }
  546.   if (leftAnalogValue < prevLeftAnalogValue) {
  547.     leftDropTime++;
  548.     if (leftDropTime > dropDelay) {
  549.       leftAnalogValue = prevLeftAnalogValue * dropFactor;
  550.       leftDropTime = 0;
  551.     }
  552.     else
  553.       leftAnalogValue = prevLeftAnalogValue;
  554.   }
  555.    
  556.   if (rightAnalogValue < prevRightAnalogValue) {
  557.     rightDropTime++;
  558.     if (rightDropTime > dropDelay) {
  559.       rightAnalogValue = prevRightAnalogValue * dropFactor;
  560.       rightDropTime = 0;
  561.     }
  562.     else
  563.       rightAnalogValue = prevRightAnalogValue;
  564.   }
  565.   #ifdef DEBUG_PRINT_ANALOGVALUES
  566.     Serial.print(leftAnalogValue);
  567.     Serial.print(" ");
  568.     Serial.println(rightAnalogValue);
  569.   #endif  
  570.   // map values  
  571.   leftValue = map(leftAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
  572.   rightValue = map(rightAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments);
  573.   
  574.   // if defined, convert to (reverse) non linear response
  575.   boolean flagNonLinear = false;
  576.   
  577.   #if defined (nonLinearSinAudio)
  578.     flagNonLinear = true;
  579.     leftValueN = ((sin(((leftValue * nonLinearResponseFactor) + 270) * 0.0174533) + 1) * maxDisplaySegments);
  580.     rightValueN = ((sin(((rightValue * nonLinearResponseFactor) + 270) * 0.0174533) + 1) * maxDisplaySegments);
  581.    
  582.   #elif defined (nonLinearReverseSinAudio)
  583.     flagNonLinear = true;
  584.     leftValueN = ((sin(((leftValue * nonLinearResponseFactor)) * 0.0174533)) * maxDisplaySegments);
  585.     rightValueN = ((sin(((rightValue * nonLinearResponseFactor)) * 0.0174533)) * maxDisplaySegments);
  586.   #elif defined (nonLinearLogAudio)
  587.     flagNonLinear = true;
  588.     leftValueN = ((log10(leftValue  + 1) / log10MaxDisplaySegments * maxDisplaySegments));
  589.     rightValueN = ((log10(rightValue  + 1) / log10MaxDisplaySegments * maxDisplaySegments));
  590.   
  591.   #endif
  592.   
  593.   if (flagNonLinear == true) {
  594.     #if defined (nonLinearAvr2)
  595.       leftValue = (leftValue + leftValueN) / 2;
  596.       rightValue = (rightValue + rightValueN) / 2;
  597.     #else
  598.       leftValue = leftValueN;
  599.       rightValue = rightValueN;
  600.     #endif
  601.   }
  602.   
  603. // @EB_DEBUG
  604.   #ifdef displayOverflow
  605.     #ifdef compressOverflowPeaks
  606.       for (i = 1; i <= compressOverflowNumOfTimes; i++) {
  607.         if (leftValue > maxDisplaySegments) {
  608. //          Serial.print(i);   
  609. //          Serial.print("  ");
  610. //          Serial.print(leftValue);   
  611. //          Serial.print("  ");
  612.           leftValue = leftValue - leftValue * compressOverflowFactor * i;
  613. //          Serial.print(leftValue);
  614. //          Serial.print("  ");
  615. //          Serial.println(maxDisplaySegments);
  616.         }
  617.       }
  618.     #endif
  619.   #endif
  620.   
  621.   if (leftValue > maxDisplaySegments) {      
  622.     leftValue = maxDisplaySegments;
  623.     #ifdef displayOverflow
  624.       drawOverflow();
  625.     #endif
  626.   }
  627.   #ifdef displayOverflow
  628.     #ifdef compressOverflowPeaks
  629.       if (rightValue > maxDisplaySegments)
  630.         rightValue = rightValue - rightValue * compressOverflowFactor;
  631.     #endif
  632.   #endif
  633.   
  634.   if (rightValue > maxDisplaySegments) {
  635.     rightValue = maxDisplaySegments;
  636.     #ifdef displayOverflow
  637.       drawOverflow();
  638.     #endif
  639.   }
  640. }
  641. void storePrevValues() {
  642.   prevLeftAnalogValue = leftAnalogValue;
  643.   prevRightAnalogValue = rightAnalogValue;
  644.   prevLeftValue = leftValue;
  645.   prevRightValue = rightValue;
  646. }
  647. void getPeaks() {
  648.   if (leftValue > leftPeak) {
  649.     if (dynamicBouncingPeaks || prevLeftPeakBounce > 0)
  650.       clearLeftBouncePeak();
  651.          
  652.     leftPeak = leftValue;
  653.     leftPeakTime = 0;
  654.     leftFirstPeak = true;
  655.     if (bouncingPeaks) {
  656.       leftPeakBouncing = true;
  657.       leftPeakBounceCounter = 0;
  658.       leftPeakBounceDelayCounter = 0;
  659.       
  660.       if (dynamicBouncingPeaks)
  661.         leftBouncingPeaksNumOfLeds = max(bouncingPeaksNumOfLedsMin, (leftPeak * bounceFactor));
  662.       else
  663.         leftBouncingPeaksNumOfLeds = bouncingPeaksNumOfLeds;
  664.     }
  665.   }
  666.   else {
  667.     leftPeakTime++;
  668.     if (droppingPeak) {
  669.       if (leftFirstPeak) {
  670.         if (leftPeakTime > peakTimeFirstDropDelay) {
  671.           clearLeftPeak();
  672.           leftFirstPeak = false;
  673.         }
  674.       }
  675.       else {
  676.         if (leftPeakTime > peakTimeDropDelay) {
  677.           clearLeftPeak();
  678.         }
  679.       }
  680.     }
  681.     else {
  682.       if (leftPeakTime > peakTimeNoDropDelay) {
  683.         clearLeftPeak();
  684.       }
  685.     }
  686.   }
  687.   if (leftPeakBouncing) {
  688.     if (leftFirstPeak) {
  689.       leftPeakBounceDelayCounter++;
  690.       if (leftPeakBounceDelayCounter >= bouncingPeakDelay) {
  691.         leftPeakBounceDelayCounter = 0;
  692.         leftPeakBounceCounter += bouncingPeakCounterInc;
  693.         if (leftPeakBounceCounter >= 180) {
  694.           clearLeftBouncePeak();
  695.           clearLeftBounce();
  696.         }
  697.         else {        
  698.           leftPeakBounce = min((sin(leftPeakBounceCounter * 0.0174533) * leftBouncingPeaksNumOfLeds), (maxDisplaySegments - leftPeak));
  699.           if (leftPeakBounce != prevLeftPeakBounce) {
  700.             clearLeftBouncePeak();
  701.           }
  702.           prevLeftPeakBounce = leftPeakBounce;
  703.         }
  704.       }
  705.     }
  706.   }
  707.   if (rightValue > rightPeak) {
  708.     if (dynamicBouncingPeaks || prevRightPeakBounce > 0)
  709.       clearRightBouncePeak();
  710.     rightPeak = rightValue;
  711.     rightPeakTime = 0;
  712.     rightFirstPeak = true;
  713.     if (bouncingPeaks) {
  714.       rightPeakBouncing = true;
  715.       rightPeakBounceCounter = 0;
  716.       rightPeakBounceDelayCounter = 0;
  717.       if (dynamicBouncingPeaks)
  718.         rightBouncingPeaksNumOfLeds = max(bouncingPeaksNumOfLedsMin, (rightPeak * bounceFactor));
  719.       else
  720.         rightBouncingPeaksNumOfLeds = bouncingPeaksNumOfLeds;
  721.     }
  722.   }
  723.   else {
  724.     rightPeakTime++;
  725.     if (droppingPeak) {
  726.       if (rightFirstPeak) {
  727.         if (rightPeakTime > peakTimeFirstDropDelay) {
  728.           clearRightPeak();
  729.           rightFirstPeak = false;
  730.         }
  731.       }
  732.       else {
  733.         if (rightPeakTime > peakTimeDropDelay)
  734.           clearRightPeak();
  735.       }
  736.     }
  737.     else {
  738.       if (rightPeakTime > peakTimeNoDropDelay)
  739.         clearRightPeak();
  740.     }
  741.   }
  742.   if (rightPeakBouncing) {
  743.     if (rightFirstPeak) {
  744.       rightPeakBounceDelayCounter++;
  745.       if (rightPeakBounceDelayCounter >= bouncingPeakDelay) {
  746.         rightPeakBounceDelayCounter = 0;
  747.         rightPeakBounceCounter += bouncingPeakCounterInc;
  748.   
  749.         if (rightPeakBounceCounter >= 180) {
  750.           clearRightBouncePeak();
  751.           clearRightBounce();
  752.         }
  753.         else {        
  754.           rightPeakBounce = min((sin(rightPeakBounceCounter * 0.0174533) * rightBouncingPeaksNumOfLeds), (maxDisplaySegments - rightPeak));
  755.           if (rightPeakBounce != prevRightPeakBounce) {
  756.             clearRightBouncePeak();
  757.           }
  758.           prevRightPeakBounce = rightPeakBounce;
  759.         }
  760.       }
  761.     }
  762.   }
  763. }
  764. void checkSpinCircle () {
  765.   if (spinCircle) {
  766.     if (spinTurnsMax == 0) {
  767.       spinTurnsMax = random(stripNumOfLeds / 4, stripNumOfLeds * 3);  // spin at least a quarter turn, max 3 turns
  768.       
  769.       if (random(10) > 4)
  770.         spinCounterInc = -spinCounterInc;
  771.       
  772.       spinTurnsDelayMax = random(100, 1000); // @EB_DEBUG
  773.       spinDelay = random(20, 75); // @EB_DEBUG
  774.     }
  775.     if (spinTurnsCounter == spinTurnsMax) {
  776.       spinTurnsDelay++;
  777.       if (spinTurnsDelay == spinTurnsDelayMax) {
  778.         spinTurnsDelay = 0;
  779.         spinTurnsCounter = 0;
  780.         spinTurnsMax = 0;
  781.       }
  782.     }
  783.     else {
  784.       spinDelayCounter++;
  785.   
  786.       if (spinDelayCounter > spinDelay) {
  787.         clearZeroAndPeaks();
  788.         spinCounter += spinCounterInc;
  789.         if (spinCounter > stripNumOfLeds)
  790.           spinCounter = 0;
  791.         else if (spinCounter < 0)
  792.           spinCounter = stripNumOfLeds;
  793.         spinTurnsCounter++;
  794.         spinDelayCounter = 0;
  795.       }
  796.     }
  797.   }
  798. }
  799. int getSpinCircleValue(int value) {
  800.   if (!spinCircle)
  801.    return value;
  802.   else {
  803.     int calcValue = value + spinCounter;
  804.     if (calcValue >= stripNumOfLeds)
  805.       calcValue -= stripNumOfLeds;
  806.     return calcValue;
  807.   }
  808. }
  809. void drawValues() {
  810.   if (splitStrip) {
  811.     for (i = middleOffset; i < leftValue; i++)
  812.       left_strip.setPixelColor(getSpinCircleValue(i), stripColor[i]);
  813.     if (!displayPeaks && displayTopAsPeak)
  814.       left_strip.setPixelColor(getSpinCircleValue(leftValue), stripHoldColor);
  815.     for (i = prevLeftValue; i >= leftValue; i--)
  816.       left_strip.setPixelColor(getSpinCircleValue(i), 0);
  817.     if (stripsOn2Pins) {
  818.       for (i = middleOffset; i < rightValue; i++)
  819.         right_strip.setPixelColor(i, stripColor[i]);
  820.       if (!displayPeaks && displayTopAsPeak)
  821.         right_strip.setPixelColor(rightValue, stripHoldColor);
  822.       for (i = prevRightValue; i >= rightValue; i--)
  823.         right_strip.setPixelColor(i, 0);
  824.     }
  825.     else {
  826.       for (i = middleOffset; i < rightValue; i++)
  827.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), stripColor[i]);
  828.       if (!displayPeaks && displayTopAsPeak)
  829.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + rightValue), stripHoldColor);
  830.         
  831.       for (i = prevRightValue; i >= rightValue; i--)
  832.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), 0);
  833.     }
  834.   }
  835.   else {
  836.     for (i = middleOffset; i < leftValue; i++)
  837.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), stripColor[i]);
  838.     if (!displayPeaks && displayTopAsPeak)
  839.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + leftValue), stripHoldColor);
  840.     for (i = prevLeftValue; i >= leftValue; i--)
  841.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), 0);
  842.   
  843.     for (i = middleOffset; i < rightValue; i++)
  844.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - i), stripColor[i]);
  845.     if (!displayPeaks && displayTopAsPeak)
  846.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - rightValue), stripHoldColor);
  847.     for (i = prevRightValue; i >= rightValue; i--)
  848.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - i), 0);
  849.   }
  850.   if (displayMiddleLed)
  851.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle), stripMiddleColor);
  852. }
  853. void drawPulsingValues() {
  854.   halfLeftValue = (leftValue + 1) / 2;
  855.   halfRightValue = (rightValue + 1) / 2;
  856.   halfPrevLeftValue = (prevLeftValue + 1)/ 2;
  857.   halfPrevRightValue = (prevRightValue + 1) / 2;
  858.   
  859.   if (splitStrip) {
  860.     for (i = 0; i < halfLeftValue; i++) {
  861.       colorValue = stripColor[i * 2];
  862.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle + i), colorValue);
  863.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle - i), colorValue);
  864.     }
  865.     if (displayTopAsPeak) {
  866.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle + halfLeftValue), stripHoldColor);
  867.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle - halfLeftValue), stripHoldColor);
  868.     }
  869.     for (i = halfPrevLeftValue; i >= halfLeftValue; i--) {
  870.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle + i), 0);
  871.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle - i), 0);
  872.     }
  873.     if (stripsOn2Pins) {
  874.       for (i = 0; i < halfRightValue; i++) {
  875.         colorValue = stripColor[i * 2];
  876.         right_strip.setPixelColor((stripPulseMiddle + i), colorValue);
  877.         right_strip.setPixelColor((stripPulseMiddle - i), colorValue);
  878.       }
  879.       if (displayTopAsPeak) {
  880.         right_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle + halfRightValue), stripHoldColor);
  881.         right_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle - halfRightValue), stripHoldColor);
  882.       }
  883.       
  884.       for (i = halfPrevRightValue; i >= halfRightValue; i--) {
  885.         right_strip.setPixelColor((stripPulseMiddle + i), 0);
  886.         right_strip.setPixelColor((stripPulseMiddle - i), 0);
  887.       }
  888.     }
  889.     else {
  890.       for (i = 0; i < halfRightValue; i++) {
  891.         colorValue = colorValue = stripColor[i * 2];
  892.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + i), colorValue);
  893.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - i), colorValue);
  894.       }
  895.       if (displayTopAsPeak) {
  896.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + halfRightValue), stripHoldColor);
  897.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - halfRightValue), stripHoldColor);
  898.       }
  899.       for (i = halfPrevRightValue; i >= halfRightValue; i--) {
  900.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + i), 0);
  901.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - i), 0);
  902.       }
  903.     }
  904.   }
  905.   else {
  906.     for (i = 0; i < halfLeftValue; i++) {
  907.       colorValue = colorValue = stripColor[i * 2];
  908.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + i), colorValue);
  909.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - i), colorValue);
  910.     }
  911.     if (displayTopAsPeak) {
  912.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + halfLeftValue), stripHoldColor);
  913.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - halfLeftValue), stripHoldColor);
  914.     }
  915.    
  916.     for (i = halfPrevLeftValue; i >= halfLeftValue; i--) {
  917.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + i), 0);
  918.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - i), 0);
  919.     }
  920.   
  921.     for (i = 0; i < halfRightValue; i++) {
  922.       colorValue = colorValue = stripColor[i * 2];
  923.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle + i)), colorValue);
  924.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle - i)), colorValue);
  925.     }
  926.     if (displayTopAsPeak) {
  927.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle + halfRightValue)), stripHoldColor);
  928.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle - halfRightValue)), stripHoldColor);
  929.     }
  930.    
  931.     for (i = halfPrevRightValue; i >= halfRightValue; i--) {
  932.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle + i)), 0);
  933.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle - i)), 0);
  934.     }
  935.   }
  936.   if (displayMiddleLed) {
  937.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle - stripPulseMiddle), stripMiddleColor);
  938.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle), stripMiddleColor);
  939.   }
  940. }
  941. void clearZeroAndPeaks() {
  942.   left_strip.setPixelColor(getSpinCircleValue(middleOffset), 0);
  943.   left_strip.setPixelColor(getSpinCircleValue(stripMiddle), 0);
  944.   if (displayTopAsPeak) {
  945.     if (splitStrip) {
  946.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle + halfLeftValue), 0);
  947.       left_strip.setPixelColor(getSpinCircleValue(stripPulseMiddle - halfLeftValue), 0);
  948.       
  949.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + halfRightValue), 0);
  950.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - halfRightValue), 0);
  951.     }
  952.     else {
  953.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle + halfLeftValue), 0);
  954.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + stripPulseMiddle - halfLeftValue), 0);
  955.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle + halfRightValue)), 0);
  956.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (stripPulseMiddle - halfRightValue)), 0);
  957.     }
  958.   }
  959. }
  960. void drawPeaks() {  
  961.   if (leftPeak > 0) {
  962.     if (droppingPeakFade && leftPeakBouncing == false)
  963.       stripHoldColor = left_strip.Color(max(1, (255 * leftPeak * ledFactor_div_numOfSegments)), 0, 0);
  964.     else
  965.       stripHoldColor = stripColor[numOfSegments];
  966.     if (splitStrip)
  967.       left_strip.setPixelColor(getSpinCircleValue(leftPeak + leftPeakBounce), stripHoldColor);
  968.     else
  969.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + (leftPeak + leftPeakBounce)), stripHoldColor);
  970.   }
  971.   
  972.   if (rightPeak > 0) {
  973.     if (droppingPeakFade && rightPeakBouncing == false)
  974.       stripHoldColor = left_strip.Color(max(1, (255 * rightPeak * ledFactor_div_numOfSegments)), 0, 0);   
  975.     else
  976.       stripHoldColor = stripColor[numOfSegments];
  977.     if (splitStrip) {
  978.       if (stripsOn2Pins) {
  979.         right_strip.setPixelColor(getSpinCircleValue(rightPeak + rightPeakBounce), stripHoldColor);
  980.       }
  981.       else {
  982.         left_strip.setPixelColor(getSpinCircleValue(stripMiddle + rightPeak + rightPeakBounce), stripHoldColor);
  983.       }
  984.     }
  985.     else {
  986.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (rightPeak + rightPeakBounce)), stripHoldColor);
  987.     }
  988.   }
  989.   //if (leftPeak > 0 || rightPeak > 0)
  990.   //  left_strip.show();   
  991. }
  992. void clearLeftPeak() {  
  993.   if (splitStrip)
  994.     left_strip.setPixelColor(getSpinCircleValue(leftPeak + prevLeftPeakBounce), 0);
  995.   else
  996.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle + (leftPeak + prevLeftPeakBounce)), 0);
  997.   if (droppingPeak)
  998.     leftPeak = leftPeak * peakDropFactor;
  999.   else
  1000.     leftPeak = 0;
  1001.   leftPeakTime = 0;
  1002. }
  1003. void clearRightPeak() {
  1004.   if (splitStrip) {
  1005.     if( stripsOn2Pins) {
  1006.       right_strip.setPixelColor(getSpinCircleValue(rightPeak + prevRightPeakBounce), 0);
  1007.     }
  1008.     else {
  1009.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + rightPeak + prevRightPeakBounce), 0);
  1010.     }
  1011.   }
  1012.   else {
  1013.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (rightPeak + prevRightPeakBounce)), 0);
  1014.   }
  1015.   
  1016.   if (droppingPeak)
  1017.     rightPeak = rightPeak * peakDropFactor;
  1018.   else
  1019.     rightPeak = 0;
  1020.   rightPeakTime = 0;
  1021. }
  1022. void clearLeftBouncePeak() {
  1023.   if (splitStrip)
  1024.     left_strip.setPixelColor(getSpinCircleValue(leftPeak + prevLeftPeakBounce), 0);
  1025.   else
  1026.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle + (leftPeak + prevLeftPeakBounce)), 0);
  1027. }
  1028. void clearRightBouncePeak() {
  1029.   if (splitStrip) {
  1030.     if (stripsOn2Pins) {
  1031.       right_strip.setPixelColor(getSpinCircleValue(rightPeak + prevRightPeakBounce), 0);
  1032.     }
  1033.     else {
  1034.       left_strip.setPixelColor(getSpinCircleValue((stripMiddle + rightPeak + prevRightPeakBounce)), 0);
  1035.     }
  1036.   }
  1037.   else {
  1038.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle - (rightPeak + prevRightPeakBounce)), 0);
  1039.   }
  1040. }
  1041. void clearLeftBounce() {
  1042.   leftPeakBouncing = false;
  1043.   leftPeakBounceCounter = 0;
  1044.   leftPeakBounce = 0;
  1045.   prevLeftPeakBounce = 0;
  1046.   leftBouncingPeaksNumOfLeds = 0;
  1047. }
  1048. void clearRightBounce() {
  1049.   rightPeakBouncing = false;
  1050.   rightPeakBounceCounter = 0;
  1051.   rightPeakBounce = 0;
  1052.   prevRightPeakBounce = 0;
  1053.   leftBouncingPeaksNumOfLeds = 0;
  1054. }
  1055. void clearValues() {
  1056.   leftAnalogValue = 0;
  1057.   rightAnalogValue = 0;
  1058.   prevLeftAnalogValue = 0;
  1059.   prevRightAnalogValue = 0;
  1060.   leftPeak = 0;
  1061.   rightPeak = 0;
  1062. }
  1063. void drawOverflow() {
  1064.   for (i = 0; i <= numOfSegments; i++) {
  1065.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle - i), stripOverflowColor);
  1066.     if (stripsOn2Pins) {
  1067.       right_strip.setPixelColor(i, stripOverflowColor);
  1068.     }
  1069.     else {
  1070.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), stripOverflowColor);
  1071.     }
  1072.   }
  1073.   left_strip.show();
  1074.   if (stripsOn2Pins)
  1075.     right_strip.show();
  1076.   
  1077.   delay(overflowDelay);
  1078.   for (i = 0; i <= numOfSegments; i++) {
  1079.     left_strip.setPixelColor(getSpinCircleValue(stripMiddle - i), 0);
  1080.     if (stripsOn2Pins) {
  1081.       right_strip.setPixelColor(i, 0);
  1082.     }
  1083.     else {
  1084.       left_strip.setPixelColor(getSpinCircleValue(stripMiddle + i), 0);
  1085.     }
  1086.   }
  1087.   left_strip.show();
  1088.   if (stripsOn2Pins)
  1089.     right_strip.show();
  1090. }
  1091. void setStripColors() {
  1092.   int r, g, b;
  1093.   int p1, p2;
  1094.   ledFactor = (float) ledBrightness / 255;
  1095.   ledFactor_div_numOfSegments = (float) ledFactor / (float) numOfSegments;
  1096.   stripMiddleColor = left_strip.Color(0, 0, 255 * ledFactor);
  1097.   
  1098.   switch (colorScheme) {
  1099.     case 0: {      
  1100.       int orangeLimit;
  1101.       float orangeFactor = orangeLimitAmount / halfNumOfSegments;
  1102.    
  1103.       for (i = 0; i <= numOfSegments; i++) {
  1104.         if (i <= halfNumOfSegments)
  1105.           orangeLimit = (i * orangeFactor);
  1106.         else
  1107.           orangeLimit = ((numOfSegments - i) * orangeFactor);
  1108.    
  1109.         stripColor[i] = left_strip.Color((255 * i * ledFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments - i) * ledFactor_div_numOfSegments), 0);
  1110.       }
  1111.       break;
  1112.     }
  1113.     case 1: {
  1114.       for (i = 0; i <= numOfSegments; i++) {
  1115.         stripColor[i] = left_strip.Color(0, (255 * i * ledFactor_div_numOfSegments), (255 * (numOfSegments - i) * ledFactor_div_numOfSegments));
  1116.       }
  1117.       break;
  1118.     }
  1119.     case 2: {
  1120.       for (i = 0; i <= numOfSegments; i++) {
  1121.         stripColor[i] = left_strip.Color((255 * i * ledFactor_div_numOfSegments), 0, (255 * (numOfSegments - i) * ledFactor_div_numOfSegments));
  1122.       }
  1123.       break;
  1124.     }
  1125.     case 3: {
  1126.       for (i = 0; i <= numOfSegments; i++) {
  1127.         stripColor[i] = left_strip.Color((255 * (numOfSegments - i) * ledFactor_div_numOfSegments), 0, (255 * i * ledFactor_div_numOfSegments));
  1128.       }
  1129.       break;
  1130.     }
  1131.     case 4: {
  1132.       for (i = 0; i <= numOfSegments; i++) {
  1133.         stripColor[i] = left_strip.Color(0, (255 * (numOfSegments - i) * ledFactor_div_numOfSegments), (255 * i * ledFactor_div_numOfSegments));
  1134.       }
  1135.       break;
  1136.     }
  1137.     case 5: {
  1138.       for (i = 0; i <= numOfSegments; i++) {
  1139.         stripColor[i] = left_strip.Color((255 * (numOfSegments - i) * ledFactor_div_numOfSegments), (255 * i * ledFactor_div_numOfSegments), 0);
  1140.       }
  1141.       break;
  1142.     }
  1143.     case 6: {
  1144.       for (i = 0; i <= numOfSegments; i++) {
  1145.         r = (255 * i * ledFactor_div_numOfSegments);
  1146.         g = (255 * min(i, numOfSegments - i) * ledFactor_div_numOfSegments);
  1147.         b = (200 * (numOfSegments - i) * ledFactor_div_numOfSegments);
  1148.         stripColor[i] = left_strip.Color(r, g, b);
  1149.       }
  1150.       break;
  1151.     }
  1152.     case 7: {
  1153.       for (i = 0; i <= numOfSegments; i++) {
  1154.         b = (255 * i * ledFactor_div_numOfSegments);
  1155.         g = (255 * min(i, numOfSegments - i) * ledFactor_div_numOfSegments);
  1156.         r = (255 * (numOfSegments - i) * ledFactor_div_numOfSegments);
  1157.         stripColor[i] = left_strip.Color(r, g, b);
  1158.       }
  1159.       break;
  1160.     }
  1161.     case 8: {
  1162.       for (i = 0; i <= numOfSegments; i++) {
  1163.         r = (255 * i * ledFactor_div_numOfSegments);
  1164.         b = (255 * min(i, numOfSegments - i) * ledFactor_div_numOfSegments);
  1165.         g = (255 * (numOfSegments - i) * ledFactor_div_numOfSegments);
  1166.         stripColor[i] = left_strip.Color(r, g, b);
  1167.       }
  1168.       break;
  1169.     }
  1170.     case 9: {
  1171.       for (i = 0; i <= numOfSegments; i++) {
  1172.         b = (255 * i * ledFactor_div_numOfSegments);
  1173.         r = (255 * min(i, numOfSegments - i) * ledFactor_div_numOfSegments);
  1174.         g = (255 * (numOfSegments - i) * ledFactor_div_numOfSegments);
  1175.         stripColor[i] = left_strip.Color(r, g, b);
  1176.       }
  1177.       break;
  1178.     }
  1179.     case 10:
  1180.       colorScheme11SpinValue = 0;
  1181.       
  1182.     case 11:     
  1183.    
  1184.     case 12: {
  1185.       p1 = (85 * numOfSegments / 255);
  1186.       p2 = (170 * numOfSegments / 255);
  1187.       int wheel;
  1188.       if (colorScheme == 12)
  1189.         colorSchemeFactor = colorScheme12Factor;        
  1190.       else
  1191.         colorSchemeFactor = 1;
  1192.             
  1193.       for (i = 0; i <= numOfSegments; i++) {  
  1194.         //wheel = int(float(i + colorScheme11SpinValue) / colorSchemeFactor) % numOfSegments;  // reverse wheel
  1195.         
  1196.         wheel = int(float(i - colorScheme11SpinValue) / colorSchemeFactor + numOfSegments) % numOfSegments;
  1197.         if (wheel < p1) {         
  1198.           wheel = map(wheel, 0, p1, 0, 255);
  1199.           r = (wheel * ledFactor);
  1200.           g = ((255 - wheel) * ledFactor);
  1201.           b = 0;
  1202.         }
  1203.         else if (wheel < p2) {
  1204.           wheel = map(wheel, p1, p2, 0, 255);
  1205.           r = ((255 - wheel) * ledFactor);
  1206.           g = 0;
  1207.           b = (wheel * ledFactor);
  1208.         }
  1209.         else {
  1210.           wheel = map(wheel, p2, numOfSegments, 0, 255);
  1211.           r = 0;
  1212.           g = (wheel * ledFactor);
  1213.           b = ((255 - wheel) * ledFactor);
  1214.         }        
  1215.         stripColor[i] = left_strip.Color(r, g, b);
  1216.       }
  1217.       break;
  1218.     }
  1219.   }
  1220.   if (colorScheme >= 10)
  1221.     stripHoldColor = left_strip.Color(255 * ledFactor, 0, 0); // set to red for the color wheels
  1222.   else
  1223.     stripHoldColor = stripColor[numOfSegments];
  1224.    
  1225.   stripOverflowColor = stripHoldColor;   // left_strip.Color(min(255, 255 * ledFactor * 1.5), 0, 0);
  1226. }
  1227. void startupAnimation() {  
  1228.   for (j = 0; j < 2; j++) {
  1229.     for (i = 0; i <= numOfSegments; i++) {
  1230.       if (animType == 1)
  1231.         left_strip.setPixelColor(stripMiddle - (numOfSegments - i), stripColor[i]);
  1232.       else
  1233.         left_strip.setPixelColor(stripMiddle - i, stripColor[i]);
  1234.       
  1235.       if (stripsOn2Pins)
  1236.         right_strip.setPixelColor(i, stripColor[i]);
  1237.       else
  1238.         left_strip.setPixelColor(stripMiddle + i, stripColor[i]);
  1239.       left_strip.show();
  1240.       if (stripsOn2Pins)
  1241.         right_strip.show();  
  1242.       
  1243.       delay(startupAnimationDelay);
  1244.     }
  1245.    
  1246.     for (i = 0; i <= numOfSegments; i++) {
  1247.       if (animType == 1)
  1248.         left_strip.setPixelColor(stripMiddle - (numOfSegments - i), 0);
  1249.       else
  1250.         left_strip.setPixelColor(stripMiddle - i, 0);
  1251.         
  1252.       if (stripsOn2Pins)
  1253.         right_strip.setPixelColor(i, 0);
  1254.       else
  1255.         left_strip.setPixelColor(stripMiddle + i, 0);
  1256.       left_strip.show();
  1257.       if (stripsOn2Pins)
  1258.         right_strip.show();  
  1259.       
  1260.       delay(startupAnimationDelay);
  1261.     }
  1262.   }
  1263. }
  1264. void displayNumber (int number, int displayDelay) {
  1265.   left_strip.clear();
  1266.   if (stripsOn2Pins)
  1267.     right_strip.clear();
  1268.   number++; // @EB_DEBUG : display value 0 at led 1
  1269.   
  1270.   for (i = 0; i <= number; i++) {
  1271.     if (i % 5 == 0)
  1272.       colorValue = stripMiddleColor;
  1273.     else
  1274.       colorValue = stripColor[0];
  1275.     left_strip.setPixelColor(middleOffset + i, colorValue);
  1276.     if (stripsOn2Pins)
  1277.       right_strip.setPixelColor(middleOffset + i, colorValue);
  1278.     else
  1279.       left_strip.setPixelColor(stripMiddle + middleOffset + i, colorValue);
  1280.     delay(45 - number * 3); // @EB_DEBUG
  1281.    
  1282.     left_strip.show();
  1283.     if (stripsOn2Pins)
  1284.       right_strip.show();  
  1285.   }
  1286.   if (pulsing) {
  1287.     left_strip.setPixelColor(middleOffset + maxDisplaySegments, stripMiddleColor);
  1288.     if (stripsOn2Pins)
  1289.       right_strip.setPixelColor(maxDisplaySegments, stripMiddleColor);
  1290.     else
  1291.       left_strip.setPixelColor(stripMiddle + maxDisplaySegments, stripMiddleColor);
  1292.     left_strip.show();
  1293.     if (stripsOn2Pins)
  1294.       right_strip.show();  
  1295.   }
  1296.   delay(displayDelay);
  1297.   left_strip.clear();
  1298.   if (stripsOn2Pins)
  1299.     right_strip.clear();
  1300. }
  1301. //
  1302. // for debugging
  1303. //
  1304. #ifdef DEBUG_TEST_LEDS
  1305.   void displayTest() {
  1306.     for (i = 0; i <= numOfSegments; i++) {
  1307.       left_strip.setPixelColor(stripMiddle - i, stripColor[i]);
  1308.       if (stripsOn2Pins)
  1309.         right_strip.setPixelColor(i, stripColor[i]);
  1310.       else
  1311.         left_strip.setPixelColor(stripMiddle + i, stripColor[i]);
  1312.       left_strip.show();
  1313.       if (stripsOn2Pins)
  1314.         right_strip.show();  
  1315.       delay(50);
  1316.     }
  1317.     delay(5000);
  1318.   
  1319.     for (i = 0; i <= numOfSegments; i++) {
  1320.       left_strip.setPixelColor(stripMiddle - i, 0);
  1321.       if (stripsOn2Pins)
  1322.         right_strip.setPixelColor(i, 0);
  1323.       else
  1324.         left_strip.setPixelColor(stripMiddle + i, 0);
  1325.       left_strip.show();
  1326.       if (stripsOn2Pins)
  1327.         right_strip.show();  
  1328.     }
  1329.   }
  1330.   
  1331.   void serialDisplayRGB(int r, int g, int b) {
  1332.     Serial.print(i);
  1333.     Serial.print(" ");
  1334.     Serial.print(r);
  1335.     Serial.print(" ");
  1336.     Serial.print(g);
  1337.     Serial.print(" ");
  1338.     Serial.println(b);
  1339.   }
  1340. #endif
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 6 小时前

多色带图案:DIY RGB 立体声 VU 表

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表
项目链接:https://www.youtube.com/watch?v= ... aiiRbVB&index=5
项目作者:HAZI-TECH

项目视频 :https://www.youtube.com/watch?v= ... aiiRbVB&index=5
项目代码:https://github.com/HAZI-TECH/Arduino-RGB-Stereo-VU-Meter

【Arduino 动手做】多色带图案:DIY RGB 立体声 VU 表图1

回复

使用道具 举报

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

本版积分规则

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

硬件清单

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

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

mail