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