Components and supplies
NeoPixel strip
Barrel Jack Female Pigtail Lead 2.1 - 5.5mm
Rotary potentiometer (generic)
Resistor 475 ohm
Resistor 10k ohm
Arduino Nano R3
Tools and machines
Soldering iron (generic)
Project description
Code
Code
arduino
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* Last updated 20171105 by ericBcreator 7* 8* This code is free for personal use, not for commercial purposes. 9* Please leave this header intact. 10* 11* contact: ericBcreator@gmail.com 12********************************************************************** 13*/ 14 15//#define DEBUG // for debugging 16 17// 18// include the NeoPixel library: 19// 20 21#include <Adafruit_NeoPixel.h> 22 23// 24// uncomment the definition for the connected strip or ring(s) 25// 26 27//#define led_ring_60 28//#define led_strip_60 29//#define led_strip_30 30//#define led_2_rings_24 31#define led_2_rings_30 32//#define led_strip_200 33//#define led_strip_144 34 35// 36// important setting: using potentiometer sensor values or not 37// This setting has to be set right or the script will not work correctly: 38// - set this to true if using potentiometers 39// - set this to false if not using potentiometers 40// 41 42const int useSensorValues = true; 43 44// 45// setup pins 46// 47 48int leftPin = A0, rightPin = A1; // left audio in on analog 0, right on analog 1 49int brightnessPin = A4, sensitivityPin = A5; // potentiometers for brightness and sensitivity on analog 4 and 5 50int stripPin = 6; // DIN of leds on digital pin 6 51int showPeaksPin = 7; // switch to toggle peaks on or off on digital pin 7 52int momentarySwitch = false; // set false for an on/off toggle switch 53 54// 55// setup variables for the number of leds and led strip or 2 rings 56// 57 58#if defined (led_ring_60) 59 //settings for a 60 led ring 60 61 int stripNumOfLeds = 32; // the total number of leds 60 idi 62 uint32_t stripColor[17]; // half of the number of leds + 1 32 idi 63 int displayMiddleLed = false; // display the middle led (blue). set to true for one strip, false for two strips or rings 64 int splitStrip = true; // set to true when using 2 strips or rings, false for one strip 65 int middleOffset = 0; // offset for the middle led when using one strip 66 int startupAnimationDelay = 6; // delay for the startup animation 67 int orangeLimitAmount = 0; // limit the amount of green of the middle LEDs to make them more orange 68 int swapLeftRight = false; // swap the left and right input values or not 69 70 int dropDelay = 4; // hold time before dropping the leds 71 float dropFactor = .92; // value for dropping the leds 72 73 int peakTimeNoDropDelay = 250; // peak hold time when not dropping the peaks (set droppingPeak true or false) 74 int peakTimeFirstDropDelay = 130; // peak hold time when dropping the first peak 75 int peakTimeDropDelay = 7; // peak hold time when dropping the rest of the peaks 76 float peakDropFactor = .93; // value for dropping the peaks 77 int droppingPeakFade = false; // display the dropping peak fading to black or not 78 79 int bouncingPeaksNumOfLeds = 6; // how many leds to bounce up (max) 80 int bouncingPeakDelay = 4; // delay between peak bounce updates 81 int bouncingPeakCounterInc = 10; // increase counter for each bounce update. note: it uses a 0-180 sin function for the bouncing 82 83#elif defined (led_strip_60) 84 //settings for a 60 led ring 85 86 int stripNumOfLeds = 60; // the total number of leds 87 uint32_t stripColor[31]; // half of the number of leds + 1 88 int displayMiddleLed = true; // display the middle led (blue). set to true for one strip, false for two strips or rings 89 int splitStrip = false; // set to true when using 2 strips or rings, false for one strip 90 int middleOffset = 1; // offset for the middle led when using one strip 91 int startupAnimationDelay = 6; // delay for the startup animation 92 int orangeLimitAmount = 0; // limit the amount of green of the middle LEDs to make them more orange 93 int swapLeftRight = false; // swap the left and right input values or not 94 95 int dropDelay = 4; // hold time before dropping the leds 96 float dropFactor = .92; // value for dropping the leds 97 98 int peakTimeNoDropDelay = 250; // peak hold time when not dropping the peaks (set droppingPeak true or false) 99 int peakTimeFirstDropDelay = 130; // peak hold time when dropping the first peak 100 int peakTimeDropDelay = 7; // peak hold time when dropping the rest of the peaks 101 float peakDropFactor = .93; // value for dropping the peaks 102 int droppingPeakFade = false; // display the dropping peak fading to black or not 103 104 int bouncingPeaksNumOfLeds = 6; // how many leds to bounce up (max) 105 int bouncingPeakDelay = 4; // delay between peak bounce updates 106 int bouncingPeakCounterInc = 10; // increase counter for each bounce update. note: it uses a 0-180 sin function for the bouncing 107 108#elif defined (led_strip_30) 109 //settings for a 30 led strip 110 111 int stripNumOfLeds = 30; // the total number of leds 112 uint32_t stripColor[16]; // half of the number of leds + 1 113 int displayMiddleLed = true; // display the middle led (blue). set to true for one strip, false for two strips or rings 114 int splitStrip = false; // set to true when using 2 strips or rings, false for one strip 115 int middleOffset = 1; // offset for the middle led when using one strip 116 int startupAnimationDelay = 10; // delay for the startup animation 117 int orangeLimitAmount = 0; // limit the amount of green of the middle LEDs to make them more orange 118 int swapLeftRight = false; // swap the left and right input values or not 119 120 int dropDelay = 10; // hold time before dropping the leds 121 float dropFactor = .9; // value for dropping the leds 122 123 int peakTimeNoDropDelay = 250; // peak hold time when not dropping the peaks (set droppingPeak true or false) 124 int peakTimeFirstDropDelay = 150; // peak hold time when dropping the first peak 125 int peakTimeDropDelay = 15; // peak hold time when dropping the rest of the peaks 126 float peakDropFactor = .94; // value for dropping the peaks 127 int droppingPeakFade = false; // display the dropping peak fading to black or not 128 129 int bouncingPeaksNumOfLeds = 3; // how many leds to bounce up (max) 130 int bouncingPeakDelay = 4; // delay between peak bounce updates 131 int bouncingPeakCounterInc = 9; // increase counter for each bounce update. note: it uses a 0-180 sin function for the bouncing 132 133#elif defined (led_2_rings_24) 134 //settings for 2 24 led rings 135 136 int stripNumOfLeds = 48; 137 uint32_t stripColor[25]; 138 int displayMiddleLed = false; 139 int splitStrip = true; 140 int middleOffset = 0; 141 int startupAnimationDelay = 5; 142 int orangeLimitAmount = 0; 143 int swapLeftRight = false; 144 145 int dropDelay = 2; 146 float dropFactor = .96; 147 148 int peakTimeNoDropDelay = 250; 149 int peakTimeFirstDropDelay = 100; 150 int peakTimeDropDelay = 10; 151 float peakDropFactor = .94; 152 int droppingPeakFade = false; 153 154 int bouncingPeaksNumOfLeds = 3; 155 int bouncingPeakDelay = 4; 156 int bouncingPeakCounterInc = 9; 157 158#elif defined(led_2_rings_30) 159 //settings for 2 30 led rings 160 161 int stripNumOfLeds = 60; 162 uint32_t stripColor[31]; 163 int displayMiddleLed = false; 164 int splitStrip = true; 165 int middleOffset = 0; 166 int startupAnimationDelay = 5; 167 int orangeLimitAmount = 0; 168 int swapLeftRight = false; 169 170 int dropDelay = 2; 171 float dropFactor = .96; 172 173 int peakTimeNoDropDelay = 250; 174 int peakTimeFirstDropDelay = 100; 175 int peakTimeDropDelay = 10; 176 float peakDropFactor = .94; 177 int droppingPeakFade = false; 178 179 int bouncingPeaksNumOfLeds = 3; 180 int bouncingPeakDelay = 4; 181 int bouncingPeakCounterInc = 9; 182 183#elif defined (led_strip_200) 184 //settings for a 200 led strip 185 186 int stripNumOfLeds = 200; 187 uint32_t stripColor[101]; 188 int displayMiddleLed = false; 189 int splitStrip = true; 190 int middleOffset = 0; 191 int startupAnimationDelay = 1; 192 int orangeLimitAmount = 0; 193 int swapLeftRight = false; 194 195 int dropDelay = 10; 196 float dropFactor = .96; 197 198 int peakTimeNoDropDelay = 250; 199 int peakTimeFirstDropDelay = 100; 200 int peakTimeDropDelay = 30; 201 float peakDropFactor = .99; 202 int droppingPeakFade = false; 203 204 int bouncingPeaksNumOfLeds = 8; 205 int bouncingPeakDelay = 4; 206 int bouncingPeakCounterInc = 9; 207 208#elif defined (led_strip_144) 209 //settings for a 200 led strip 210 211 int stripNumOfLeds = 145; 212 uint32_t stripColor[73]; 213 int displayMiddleLed = true; 214 int splitStrip = false; 215 int middleOffset = 1; 216 int startupAnimationDelay = 1; 217 int orangeLimitAmount = 0; 218 int swapLeftRight = false; 219 220 int dropDelay = 10; 221 float dropFactor = .85; 222 223 int peakTimeNoDropDelay = 250; 224 int peakTimeFirstDropDelay = 100; 225 int peakTimeDropDelay = 5; 226 float peakDropFactor = .94; 227 int droppingPeakFade = false; 228 229 int bouncingPeaksNumOfLeds = 10; 230 int bouncingPeakDelay = 2; 231 int bouncingPeakCounterInc = 10; 232#endif 233 234// 235// setup other variables, user editable 236// 237 238// basic settings 239int minValue = 5; // min analog input value 240int maxValue = 250; // max analog input value (0-1023 equals 0-5V) 241int sensitivityValue = 255; // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true) 242int maxSensitivity = 2 * 255; // let the 'volume' go up to 200%! 243int ledBrightness = 30; // 0 - 255, initial value (value read from the potentiometer if useSensorValues = true) 244int sensorDeviationBrightness = 1; // eliminate fluctuating values 245int overflowDelay = 20; // overflow hold time 246 247// peak settings 248int displayPeaks = true; // value will be set by the switch if useSensorValues = true 249int droppingPeak = true; // display dropping peaks or not. note: displayPeaks has to be true 250int bouncingPeaks = true; // display bouncing peaks or not. note: displayPeaks has to be true 251 252// 253// initialize other variables needed for the sketch 254// 255 256int numOfSegments = stripNumOfLeds / 2; 257int halfNumOfSegments = numOfSegments / 2; 258int stripMiddle = stripNumOfLeds / 2; 259int maxDisplaySegments = stripMiddle - 1; 260float sensitivityFactor; 261 262int brightnessValue, prevBrightnessValue; 263float ledFactor, ledFactor_div_numOfSegments; 264 265int leftValue = 0, rightValue = 0, maxReadValue = 0; 266int leftAnalogValue = 0, rightAnalogValue = 0; 267 268int prevLeftValue = 0, prevRightValue = 0; 269int prevLeftAnalogValue = 0, prevRightAnalogValue = 0; 270 271int i, j; 272int dropLeft, dropRight; 273int leftDropTime, rightDropTime; 274 275int leftPeak = 0, rightPeak = 0; 276int leftPeakTime = 0, rightPeakTime = 0; 277int leftFirstPeak = true, rightFirstPeak = true; 278int readShowPeaksPin, prevReadShowPeaksPin; 279 280uint32_t stripMiddleColor, stripOverflowColor, stripHoldColor; 281 282int leftPeakBouncing = false, rightPeakBouncing = false; 283int leftPeakBounce = 0, rightPeakBounce = 0; 284int prevLeftPeakBounce = 0, prevRightPeakBounce = 0; 285int leftPeakBounceCounter = 0, rightPeakBounceCounter = 0; 286int leftPeakBounceDelayCounter = 0, rightPeakBounceDelayCounter = 0; 287 288// 289// initialize the strip or rings 290// 291 292Adafruit_NeoPixel strip = Adafruit_NeoPixel(stripNumOfLeds, stripPin, NEO_GRB + NEO_KHZ800); 293 294// 295// setup 296// 297 298void setup() { 299 #ifdef DEBUG 300 Serial.begin(9600); 301 #endif 302 303 pinMode(showPeaksPin, INPUT); 304 305 strip.begin(); 306 307 setStripColors(); 308 startupAnimation(); 309 310 if (useSensorValues) 311 setInitialDisplayPeaks(); 312 else 313 setSensitivityFactor(); 314} 315 316// 317// main loop 318// 319 320void loop() { 321 if (useSensorValues) 322 readSensorValues(); 323 324 readValues(); 325 drawValues(); 326 327 if (displayPeaks) { 328 getPeaks(); 329 drawPeaks(); 330 } 331 332 storePrevValues(); 333} 334 335// 336// functions 337// 338 339void setInitialDisplayPeaks() { 340 readShowPeaksPin = digitalRead(showPeaksPin); 341 if (readShowPeaksPin == HIGH) 342 displayPeaks = false; 343 else 344 displayPeaks = true; 345 prevReadShowPeaksPin = readShowPeaksPin; 346} 347 348void readSensorValues() { 349 readShowPeaksPin = digitalRead(showPeaksPin); 350 351 if (momentarySwitch) { 352 if (readShowPeaksPin == LOW && prevReadShowPeaksPin == HIGH) { 353 if (displayPeaks == true) { 354 displayPeaks = false; 355 clearLeftPeak(); 356 clearRightPeak(); 357 if (momentarySwitch) 358 while (digitalRead(showPeaksPin) == LOW) {} 359 } 360 else { 361 displayPeaks = true; 362 } 363 } 364 } 365 else { 366 if (readShowPeaksPin == LOW && prevReadShowPeaksPin == HIGH) 367 displayPeaks = true; 368 else if (readShowPeaksPin == HIGH && prevReadShowPeaksPin == LOW) { 369 displayPeaks = false; 370 clearLeftPeak(); 371 clearRightPeak(); 372 } 373 } 374 prevReadShowPeaksPin = readShowPeaksPin; 375 376 brightnessValue = analogRead(brightnessPin); 377 brightnessValue = map(brightnessValue, 0, 1023, 0, 255); 378 379 if (abs(brightnessValue - prevBrightnessValue) > sensorDeviationBrightness) { 380 ledBrightness = brightnessValue; 381 setStripColors(); 382 prevBrightnessValue = brightnessValue; 383 } 384 385 sensitivityValue = analogRead(sensitivityPin); 386 sensitivityValue = map(sensitivityValue, 0, 1023, 0, 255); 387 setSensitivityFactor(); 388} 389 390void setSensitivityFactor() { 391 //sensitivityValue_div_numOfSegments = sensitivityValue / numOfSegments; 392 sensitivityFactor = ((float) sensitivityValue / 255 * (float) maxSensitivity / 255); 393} 394 395void readValues() { 396 leftAnalogValue = analogRead(leftPin); 397 rightAnalogValue = analogRead(rightPin); 398 399 if (swapLeftRight) { 400 int tempValue = leftAnalogValue; 401 leftAnalogValue = rightAnalogValue; 402 rightAnalogValue = tempValue; 403 } 404 405 if (leftAnalogValue < prevLeftAnalogValue) { 406 leftDropTime++; 407 if (leftDropTime > dropDelay) { 408 leftAnalogValue = prevLeftAnalogValue * dropFactor; 409 leftDropTime = 0; 410 } 411 else 412 leftAnalogValue = prevLeftAnalogValue; 413 } 414 415 if (rightAnalogValue < prevRightAnalogValue) { 416 rightDropTime++; 417 if (rightDropTime > dropDelay) { 418 rightAnalogValue = prevRightAnalogValue * dropFactor; 419 rightDropTime = 0; 420 } 421 else 422 rightAnalogValue = prevRightAnalogValue; 423 } 424 425 #ifdef DEBUG 426 Serial.print(leftAnalogValue); 427 Serial.print(" "); 428 Serial.println(rightAnalogValue); 429 #endif 430 431 // map values 432 leftValue = map(leftAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments); 433 rightValue = map(rightAnalogValue * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments); 434 435 if (leftValue > maxDisplaySegments) { 436 leftValue = maxDisplaySegments; 437 drawOverflow(); 438 } 439 440 if (rightValue > maxDisplaySegments) { 441 rightValue = maxDisplaySegments; 442 drawOverflow(); 443 } 444} 445 446void storePrevValues() { 447 prevLeftAnalogValue = leftAnalogValue; 448 prevRightAnalogValue = rightAnalogValue; 449 450 prevLeftValue = leftValue; 451 prevRightValue = rightValue; 452} 453 454void getPeaks() { 455 if (leftValue > leftPeak) { 456 leftPeak = leftValue; 457 leftPeakTime = 0; 458 leftFirstPeak = true; 459 460 if (bouncingPeaks) { 461 leftPeakBouncing = true; 462 leftPeakBounceCounter = 0; 463 leftPeakBounceDelayCounter = 0; 464 } 465 } 466 else { 467 leftPeakTime++; 468 if (droppingPeak) { 469 if (leftFirstPeak) { 470 if (leftPeakTime > peakTimeFirstDropDelay) { 471 clearLeftPeak(); 472 leftFirstPeak = false; 473 } 474 } 475 else { 476 if (leftPeakTime > peakTimeDropDelay) { 477 clearLeftPeak(); 478 } 479 } 480 } 481 else { 482 if (leftPeakTime > peakTimeNoDropDelay) { 483 clearLeftPeak(); 484 } 485 } 486 } 487 488 if (leftPeakBouncing) { 489 if (leftFirstPeak) { 490 leftPeakBounceDelayCounter++; 491 if (leftPeakBounceDelayCounter >= bouncingPeakDelay) { 492 leftPeakBounceDelayCounter = 0; 493 leftPeakBounceCounter += bouncingPeakCounterInc; 494 495 if (leftPeakBounceCounter >= 180) { 496 clearLeftBouncePeak(); 497 clearLeftBounce(); 498 } 499 else { 500 leftPeakBounce = min((sin(leftPeakBounceCounter * 0.0174532925) * bouncingPeaksNumOfLeds), (maxDisplaySegments - leftPeak)); 501 if (leftPeakBounce != prevLeftPeakBounce) { 502 clearLeftBouncePeak(); 503 } 504 prevLeftPeakBounce = leftPeakBounce; 505 } 506 } 507 } 508 } 509 510 if (rightValue > rightPeak) { 511 rightPeak = rightValue; 512 rightPeakTime = 0; 513 rightFirstPeak = true; 514 515 if (bouncingPeaks) { 516 rightPeakBouncing = true; 517 rightPeakBounceCounter = 0; 518 rightPeakBounceDelayCounter = 0; 519 } 520 } 521 else { 522 rightPeakTime++; 523 if (droppingPeak) { 524 if (rightFirstPeak) { 525 if (rightPeakTime > peakTimeFirstDropDelay) { 526 clearRightPeak(); 527 rightFirstPeak = false; 528 } 529 } 530 else { 531 if (rightPeakTime > peakTimeDropDelay) 532 clearRightPeak(); 533 } 534 } 535 else { 536 if (rightPeakTime > peakTimeNoDropDelay) 537 clearRightPeak(); 538 } 539 } 540 541 if (rightPeakBouncing) { 542 if (rightFirstPeak) { 543 rightPeakBounceDelayCounter++; 544 if (rightPeakBounceDelayCounter >= bouncingPeakDelay) { 545 rightPeakBounceDelayCounter = 0; 546 rightPeakBounceCounter += bouncingPeakCounterInc; 547 548 if (rightPeakBounceCounter >= 180) { 549 clearRightBouncePeak(); 550 clearRightBounce(); 551 } 552 else { 553 rightPeakBounce = min((sin(rightPeakBounceCounter * 0.0174532925) * bouncingPeaksNumOfLeds), (maxDisplaySegments - rightPeak)); 554 if (rightPeakBounce != prevRightPeakBounce) { 555 clearRightBouncePeak(); 556 } 557 prevRightPeakBounce = rightPeakBounce; 558 } 559 } 560 } 561 } 562} 563 564void drawValues() { 565 if (splitStrip) { 566 for (i = middleOffset; i < leftValue; i++) 567 strip.setPixelColor(i, stripColor[i]); 568 569 for (i = prevLeftValue; i > leftValue; i--) 570 strip.setPixelColor(i, 0); 571 572 for (i = middleOffset; i < rightValue; i++) 573 strip.setPixelColor(stripMiddle + i, stripColor[i]); 574 575 for (i = prevRightValue; i > rightValue; i--) 576 strip.setPixelColor(stripMiddle + i, 0); 577 } 578 else { 579 for (i = middleOffset; i < leftValue; i++) 580 strip.setPixelColor(stripMiddle + i, stripColor[i]); 581 582 for (i = prevLeftValue; i > leftValue; i--) 583 strip.setPixelColor(stripMiddle + i, 0); 584 585 for (i = middleOffset; i < rightValue; i++) 586 strip.setPixelColor(stripMiddle - i, stripColor[i]); 587 588 for (i = prevRightValue; i > rightValue; i--) 589 strip.setPixelColor(stripMiddle - i, 0); 590 } 591 592 if (displayMiddleLed) strip.setPixelColor(stripMiddle, stripMiddleColor); 593 strip.show(); 594} 595 596void drawPeaks() { 597 if (leftPeak > 0) { 598 if (droppingPeakFade && leftPeakBouncing == false) 599 stripHoldColor = strip.Color(max(1, (255 * leftPeak * ledFactor_div_numOfSegments)), 0, 0); 600 else 601 stripHoldColor = stripColor[numOfSegments]; 602 603 if (splitStrip) 604 strip.setPixelColor((leftPeak + leftPeakBounce), stripHoldColor); 605 else 606 strip.setPixelColor(stripMiddle + (leftPeak + leftPeakBounce), stripHoldColor); 607 } 608 609 if (rightPeak > 0) { 610 if (droppingPeakFade && rightPeakBouncing == false) 611 stripHoldColor = strip.Color(max(1, (255 * rightPeak * ledFactor_div_numOfSegments)), 0, 0); 612 else 613 stripHoldColor = stripColor[numOfSegments]; 614 615 if (splitStrip) 616 strip.setPixelColor(stripMiddle + rightPeak + prevRightPeakBounce, stripHoldColor); 617 else 618 strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), stripHoldColor); 619 } 620 621 if (leftPeak > 0 || rightPeak > 0) 622 strip.show(); 623} 624 625void clearLeftPeak() { 626 if (splitStrip) 627 strip.setPixelColor((leftPeak + prevLeftPeakBounce), 0); 628 else 629 strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 0); 630 631 if (droppingPeak) 632 leftPeak = leftPeak * peakDropFactor; 633 else 634 leftPeak = 0; 635 leftPeakTime = 0; 636} 637 638void clearLeftBounce() { 639 leftPeakBouncing = false; 640 leftPeakBounceCounter = 0; 641 leftPeakBounce = 0; 642 prevLeftPeakBounce = 0; 643} 644 645void clearLeftBouncePeak() { 646 if (splitStrip) 647 strip.setPixelColor((leftPeak + prevLeftPeakBounce), 0); 648 else 649 strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 0); 650} 651 652void clearRightPeak() { 653 if (splitStrip) 654 strip.setPixelColor(stripMiddle + rightPeak + prevRightPeakBounce, 0); 655 else 656 strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), 0); 657 658 if (droppingPeak) 659 rightPeak = rightPeak * peakDropFactor; 660 else 661 rightPeak = 0; 662 rightPeakTime = 0; 663} 664 665void clearRightBounce() { 666 rightPeakBouncing = false; 667 rightPeakBounceCounter = 0; 668 rightPeakBounce = 0; 669 prevRightPeakBounce = 0; 670} 671 672void clearRightBouncePeak() { 673 if (splitStrip) 674 strip.setPixelColor((stripMiddle + rightPeak + prevRightPeakBounce), 0); 675 else 676 strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), 0); 677} 678 679void drawOverflow() { 680 for (i = 0; i <= numOfSegments; i++) { 681 strip.setPixelColor(stripMiddle + i, stripOverflowColor); 682 strip.setPixelColor(stripMiddle - i, stripOverflowColor); 683 } 684 strip.show(); 685 delay(overflowDelay); 686 687 for (i = 0; i <= numOfSegments; i++) { 688 strip.setPixelColor(stripMiddle + i, 0); 689 strip.setPixelColor(stripMiddle - i, 0); 690 } 691 strip.show(); 692} 693 694void setStripColors() { 695 int orangeLimit; 696 ledFactor = (float)ledBrightness / 255; 697 698 float orangeFactor = orangeLimitAmount / halfNumOfSegments; 699 ledFactor_div_numOfSegments = ledFactor / numOfSegments; 700 701 stripOverflowColor = strip.Color(min(255, 255 * ledFactor * 1.5), 0, 0); 702 stripMiddleColor = strip.Color(0, 0, 255 * ledFactor); 703 704 stripColor[0] = strip.Color(0, 255 * ledFactor, 0); 705 for (i = 1; i <= numOfSegments; i++) { 706 if (i <= halfNumOfSegments) 707 orangeLimit = (i * orangeFactor); 708 else 709 orangeLimit = ((numOfSegments - i) * orangeFactor); 710 711 stripColor[i] = strip.Color((255 * i * ledFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments - i) * ledFactor_div_numOfSegments), 0); 712 } 713 714 stripHoldColor = stripColor[numOfSegments]; 715} 716 717void startupAnimation() { 718 for (j = 0; j < 2; j++) { 719 for (i = 0; i <= numOfSegments; i++) { 720 strip.setPixelColor(stripMiddle - i, stripColor[i]); 721 strip.setPixelColor(stripMiddle + i, stripColor[i]); 722 strip.show(); 723 delay(startupAnimationDelay); 724 } 725 726 for (i = 0; i <= numOfSegments; i++) { 727 strip.setPixelColor(stripMiddle + i, 0); 728 strip.setPixelColor(stripMiddle - i, 0); 729 strip.show(); 730 delay(startupAnimationDelay); 731 } 732 } 733} 734
Code
arduino
1/* 2********************************************************************** 3* 4 Stereo VU Meter for 1 or 2 LED rings or strips build by ericBcreator 5* Designed 6 to be used with an Arduino UNO, Nano or compatible device. 7********************************************************************** 8* 9 Last updated 20171105 by ericBcreator 10* 11* This code is free for personal use, 12 not for commercial purposes. 13* Please leave this header intact. 14* 15* contact: 16 ericBcreator@gmail.com 17********************************************************************** 18*/ 19 20//#define 21 DEBUG // for debugging 22 23// 24// 25 include the NeoPixel library: 26// 27 28#include <Adafruit_NeoPixel.h> 29 30// 31// 32 uncomment the definition for the connected strip or ring(s) 33// 34 35//#define 36 led_ring_60 37//#define led_strip_60 38//#define led_strip_30 39//#define led_2_rings_24 40#define 41 led_2_rings_30 42//#define led_strip_200 43//#define led_strip_144 44 45// 46// 47 important setting: using potentiometer sensor values or not 48// This setting has 49 to be set right or the script will not work correctly: 50// - set this to true 51 if using potentiometers 52// - set this to false if not using potentiometers 53// 54 55const 56 int useSensorValues = true; 57 58// 59// setup pins 60// 61 62int 63 leftPin = A0, rightPin = A1; // left audio in on analog 64 0, right on analog 1 65int brightnessPin = A4, sensitivityPin = A5; // 66 potentiometers for brightness and sensitivity on analog 4 and 5 67int stripPin 68 = 6; // DIN of leds on digital pin 6 69int 70 showPeaksPin = 7; // switch to toggle peaks 71 on or off on digital pin 7 72int momentarySwitch = false; // 73 set false for an on/off toggle switch 74 75// 76// setup variables for the number 77 of leds and led strip or 2 rings 78// 79 80#if defined (led_ring_60) 81 //settings 82 for a 60 led ring 83 84 int stripNumOfLeds = 32; // 85 the total number of leds 60 idi 86 uint32_t stripColor[17]; // 87 half of the number of leds + 1 32 idi 88 int displayMiddleLed = false; // 89 display the middle led (blue). set to true for one strip, false for two strips or 90 rings 91 int splitStrip = true; // set to true 92 when using 2 strips or rings, false for one strip 93 int middleOffset = 0; // 94 offset for the middle led when using one strip 95 int startupAnimationDelay = 96 6; // delay for the startup animation 97 int orangeLimitAmount 98 = 0; // limit the amount of green of the middle LEDs 99 to make them more orange 100 int swapLeftRight = false; // 101 swap the left and right input values or not 102 103 int dropDelay = 4; // 104 hold time before dropping the leds 105 float dropFactor = .92; // 106 value for dropping the leds 107 108 int peakTimeNoDropDelay = 250; // 109 peak hold time when not dropping the peaks (set droppingPeak true or false) 110 111 int peakTimeFirstDropDelay = 130; // peak hold time when 112 dropping the first peak 113 int peakTimeDropDelay = 7; // 114 peak hold time when dropping the rest of the peaks 115 float peakDropFactor = .93; 116 // value for dropping the peaks 117 int droppingPeakFade 118 = false; // display the dropping peak fading to black 119 or not 120 121 int bouncingPeaksNumOfLeds = 6; // how 122 many leds to bounce up (max) 123 int bouncingPeakDelay = 4; // 124 delay between peak bounce updates 125 int bouncingPeakCounterInc = 10; // 126 increase counter for each bounce update. note: it uses a 0-180 sin function for 127 the bouncing 128 129#elif defined (led_strip_60) 130 //settings for a 60 led ring 131 132 133 int stripNumOfLeds = 60; // the total number 134 of leds 135 uint32_t stripColor[31]; // half of 136 the number of leds + 1 137 int displayMiddleLed = true; // 138 display the middle led (blue). set to true for one strip, false for two strips or 139 rings 140 int splitStrip = false; // set to true 141 when using 2 strips or rings, false for one strip 142 int middleOffset = 1; // 143 offset for the middle led when using one strip 144 int startupAnimationDelay = 145 6; // delay for the startup animation 146 int orangeLimitAmount 147 = 0; // limit the amount of green of the middle LEDs 148 to make them more orange 149 int swapLeftRight = false; // 150 swap the left and right input values or not 151 152 int dropDelay = 4; // 153 hold time before dropping the leds 154 float dropFactor = .92; // 155 value for dropping the leds 156 157 int peakTimeNoDropDelay = 250; // 158 peak hold time when not dropping the peaks (set droppingPeak true or false) 159 160 int peakTimeFirstDropDelay = 130; // peak hold time when 161 dropping the first peak 162 int peakTimeDropDelay = 7; // 163 peak hold time when dropping the rest of the peaks 164 float peakDropFactor = .93; 165 // value for dropping the peaks 166 int droppingPeakFade 167 = false; // display the dropping peak fading to black 168 or not 169 170 int bouncingPeaksNumOfLeds = 6; // how 171 many leds to bounce up (max) 172 int bouncingPeakDelay = 4; // 173 delay between peak bounce updates 174 int bouncingPeakCounterInc = 10; // 175 increase counter for each bounce update. note: it uses a 0-180 sin function for 176 the bouncing 177 178#elif defined (led_strip_30) 179 //settings for a 30 led strip 180 181 182 int stripNumOfLeds = 30; // the total number 183 of leds 184 uint32_t stripColor[16]; // half of 185 the number of leds + 1 186 int displayMiddleLed = true; // 187 display the middle led (blue). set to true for one strip, false for two strips or 188 rings 189 int splitStrip = false; // set to true 190 when using 2 strips or rings, false for one strip 191 int middleOffset = 1; // 192 offset for the middle led when using one strip 193 int startupAnimationDelay = 194 10; // delay for the startup animation 195 int orangeLimitAmount 196 = 0; // limit the amount of green of the middle LEDs 197 to make them more orange 198 int swapLeftRight = false; // 199 swap the left and right input values or not 200 201 int dropDelay = 10; // 202 hold time before dropping the leds 203 float dropFactor = .9; // 204 value for dropping the leds 205 206 int peakTimeNoDropDelay = 250; // 207 peak hold time when not dropping the peaks (set droppingPeak true or false) 208 209 int peakTimeFirstDropDelay = 150; // peak hold time when 210 dropping the first peak 211 int peakTimeDropDelay = 15; // 212 peak hold time when dropping the rest of the peaks 213 float peakDropFactor = .94; 214 // value for dropping the peaks 215 int droppingPeakFade 216 = false; // display the dropping peak fading to black 217 or not 218 219 int bouncingPeaksNumOfLeds = 3; // how 220 many leds to bounce up (max) 221 int bouncingPeakDelay = 4; // 222 delay between peak bounce updates 223 int bouncingPeakCounterInc = 9; // 224 increase counter for each bounce update. note: it uses a 0-180 sin function for 225 the bouncing 226 227#elif defined (led_2_rings_24) 228 //settings for 2 24 led 229 rings 230 231 int stripNumOfLeds = 48; 232 uint32_t stripColor[25]; 233 int displayMiddleLed 234 = false; 235 int splitStrip = true; 236 int middleOffset = 0; 237 int startupAnimationDelay 238 = 5; 239 int orangeLimitAmount = 0; 240 int swapLeftRight = false; 241 242 int 243 dropDelay = 2; 244 float dropFactor = .96; 245 246 int peakTimeNoDropDelay = 247 250; 248 int peakTimeFirstDropDelay = 100; 249 int peakTimeDropDelay = 10; 250 251 float peakDropFactor = .94; 252 int droppingPeakFade = false; 253 254 int 255 bouncingPeaksNumOfLeds = 3; 256 int bouncingPeakDelay = 4; 257 int bouncingPeakCounterInc 258 = 9; 259 260#elif defined(led_2_rings_30) 261 //settings for 2 30 led rings 262 263 264 int stripNumOfLeds = 60; 265 uint32_t stripColor[31]; 266 int displayMiddleLed 267 = false; 268 int splitStrip = true; 269 int middleOffset = 0; 270 int startupAnimationDelay 271 = 5; 272 int orangeLimitAmount = 0; 273 int swapLeftRight = false; 274 275 int 276 dropDelay = 2; 277 float dropFactor = .96; 278 279 int peakTimeNoDropDelay = 280 250; 281 int peakTimeFirstDropDelay = 100; 282 int peakTimeDropDelay = 10; 283 284 float peakDropFactor = .94; 285 int droppingPeakFade = false; 286 287 int 288 bouncingPeaksNumOfLeds = 3; 289 int bouncingPeakDelay = 4; 290 int bouncingPeakCounterInc 291 = 9; 292 293#elif defined (led_strip_200) 294 //settings for a 200 led strip 295 296 297 int stripNumOfLeds = 200; 298 uint32_t stripColor[101]; 299 int displayMiddleLed 300 = false; 301 int splitStrip = true; 302 int middleOffset = 0; 303 int startupAnimationDelay 304 = 1; 305 int orangeLimitAmount = 0; 306 int swapLeftRight = false; 307 308 int 309 dropDelay = 10; 310 float dropFactor = .96; 311 312 int peakTimeNoDropDelay 313 = 250; 314 int peakTimeFirstDropDelay = 100; 315 int peakTimeDropDelay = 30; 316 317 float peakDropFactor = .99; 318 int droppingPeakFade = false; 319 320 int 321 bouncingPeaksNumOfLeds = 8; 322 int bouncingPeakDelay = 4; 323 int bouncingPeakCounterInc 324 = 9; 325 326#elif defined (led_strip_144) 327 //settings for a 200 led strip 328 329 330 int stripNumOfLeds = 145; 331 uint32_t stripColor[73]; 332 int displayMiddleLed 333 = true; 334 int splitStrip = false; 335 int middleOffset = 1; 336 int startupAnimationDelay 337 = 1; 338 int orangeLimitAmount = 0; 339 int swapLeftRight = false; 340 341 int 342 dropDelay = 10; 343 float dropFactor = .85; 344 345 int peakTimeNoDropDelay 346 = 250; 347 int peakTimeFirstDropDelay = 100; 348 int peakTimeDropDelay = 5; 349 350 float peakDropFactor = .94; 351 int droppingPeakFade = false; 352 353 int 354 bouncingPeaksNumOfLeds = 10; 355 int bouncingPeakDelay = 2; 356 int bouncingPeakCounterInc 357 = 10; 358#endif 359 360// 361// setup other variables, user editable 362// 363 364// 365 basic settings 366int minValue = 5; // min 367 analog input value 368int maxValue = 250; // 369 max analog input value (0-1023 equals 0-5V) 370int sensitivityValue = 255; // 371 0 - 255, initial value (value read from the potentiometer if useSensorValues = true) 372int 373 maxSensitivity = 2 * 255; // let the 'volume' go up 374 to 200%! 375int ledBrightness = 30; // 0 - 255, 376 initial value (value read from the potentiometer if useSensorValues = true) 377int 378 sensorDeviationBrightness = 1; // eliminate fluctuating values 379int 380 overflowDelay = 20; // overflow hold time 381 382// 383 peak settings 384int displayPeaks = true; // value 385 will be set by the switch if useSensorValues = true 386int droppingPeak = true; 387 // display dropping peaks or not. note: displayPeaks 388 has to be true 389int bouncingPeaks = true; // 390 display bouncing peaks or not. note: displayPeaks has to be true 391 392// 393// 394 initialize other variables needed for the sketch 395// 396 397int numOfSegments 398 = stripNumOfLeds / 2; 399int halfNumOfSegments = numOfSegments / 2; 400int stripMiddle 401 = stripNumOfLeds / 2; 402int maxDisplaySegments = stripMiddle - 1; 403float sensitivityFactor; 404 405int 406 brightnessValue, prevBrightnessValue; 407float ledFactor, ledFactor_div_numOfSegments; 408 409int 410 leftValue = 0, rightValue = 0, maxReadValue = 0; 411int leftAnalogValue = 0, rightAnalogValue 412 = 0; 413 414int prevLeftValue = 0, prevRightValue = 0; 415int prevLeftAnalogValue 416 = 0, prevRightAnalogValue = 0; 417 418int i, j; 419int dropLeft, dropRight; 420int 421 leftDropTime, rightDropTime; 422 423int leftPeak = 0, rightPeak = 0; 424int leftPeakTime 425 = 0, rightPeakTime = 0; 426int leftFirstPeak = true, rightFirstPeak = true; 427int 428 readShowPeaksPin, prevReadShowPeaksPin; 429 430uint32_t stripMiddleColor, stripOverflowColor, 431 stripHoldColor; 432 433int leftPeakBouncing = false, rightPeakBouncing = false; 434int 435 leftPeakBounce = 0, rightPeakBounce = 0; 436int prevLeftPeakBounce = 0, prevRightPeakBounce 437 = 0; 438int leftPeakBounceCounter = 0, rightPeakBounceCounter = 0; 439int leftPeakBounceDelayCounter 440 = 0, rightPeakBounceDelayCounter = 0; 441 442// 443// initialize the strip or rings 444// 445 446Adafruit_NeoPixel 447 strip = Adafruit_NeoPixel(stripNumOfLeds, stripPin, NEO_GRB + NEO_KHZ800); 448 449// 450// 451 setup 452// 453 454void setup() { 455 #ifdef DEBUG 456 Serial.begin(9600); 457 458 #endif 459 460 pinMode(showPeaksPin, INPUT); 461 462 strip.begin(); 463 464 465 setStripColors(); 466 startupAnimation(); 467 468 if (useSensorValues) 469 470 setInitialDisplayPeaks(); 471 else 472 setSensitivityFactor(); 473} 474 475// 476// 477 main loop 478// 479 480void loop() { 481 if (useSensorValues) 482 readSensorValues(); 483 484 485 readValues(); 486 drawValues(); 487 488 if (displayPeaks) { 489 getPeaks(); 490 491 drawPeaks(); 492 } 493 494 storePrevValues(); 495} 496 497// 498// functions 499// 500 501void 502 setInitialDisplayPeaks() { 503 readShowPeaksPin = digitalRead(showPeaksPin); 504 505 if (readShowPeaksPin == HIGH) 506 displayPeaks = false; 507 else 508 displayPeaks 509 = true; 510 prevReadShowPeaksPin = readShowPeaksPin; 511} 512 513void readSensorValues() 514 { 515 readShowPeaksPin = digitalRead(showPeaksPin); 516 517 if (momentarySwitch) 518 { 519 if (readShowPeaksPin == LOW && prevReadShowPeaksPin == HIGH) { 520 if 521 (displayPeaks == true) { 522 displayPeaks = false; 523 clearLeftPeak(); 524 525 clearRightPeak(); 526 if (momentarySwitch) 527 while 528 (digitalRead(showPeaksPin) == LOW) {} 529 } 530 else { 531 displayPeaks 532 = true; 533 } 534 } 535 } 536 else { 537 if (readShowPeaksPin == LOW 538 && prevReadShowPeaksPin == HIGH) 539 displayPeaks = true; 540 else if (readShowPeaksPin 541 == HIGH && prevReadShowPeaksPin == LOW) { 542 displayPeaks = false; 543 clearLeftPeak(); 544 545 clearRightPeak(); 546 } 547 } 548 prevReadShowPeaksPin = readShowPeaksPin; 549 550 551 brightnessValue = analogRead(brightnessPin); 552 brightnessValue = map(brightnessValue, 553 0, 1023, 0, 255); 554 555 if (abs(brightnessValue - prevBrightnessValue) > sensorDeviationBrightness) 556 { 557 ledBrightness = brightnessValue; 558 setStripColors(); 559 prevBrightnessValue 560 = brightnessValue; 561 } 562 563 sensitivityValue = analogRead(sensitivityPin); 564 565 sensitivityValue = map(sensitivityValue, 0, 1023, 0, 255); 566 setSensitivityFactor(); 567} 568 569void 570 setSensitivityFactor() { 571 //sensitivityValue_div_numOfSegments = sensitivityValue 572 / numOfSegments; 573 sensitivityFactor = ((float) sensitivityValue / 255 * (float) 574 maxSensitivity / 255); 575} 576 577void readValues() { 578 leftAnalogValue = analogRead(leftPin); 579 580 rightAnalogValue = analogRead(rightPin); 581 582 if (swapLeftRight) { 583 int 584 tempValue = leftAnalogValue; 585 leftAnalogValue = rightAnalogValue; 586 rightAnalogValue 587 = tempValue; 588 } 589 590 if (leftAnalogValue < prevLeftAnalogValue) { 591 leftDropTime++; 592 593 if (leftDropTime > dropDelay) { 594 leftAnalogValue = prevLeftAnalogValue 595 * dropFactor; 596 leftDropTime = 0; 597 } 598 else 599 leftAnalogValue 600 = prevLeftAnalogValue; 601 } 602 603 if (rightAnalogValue < prevRightAnalogValue) 604 { 605 rightDropTime++; 606 if (rightDropTime > dropDelay) { 607 rightAnalogValue 608 = prevRightAnalogValue * dropFactor; 609 rightDropTime = 0; 610 } 611 else 612 613 rightAnalogValue = prevRightAnalogValue; 614 } 615 616 #ifdef DEBUG 617 618 Serial.print(leftAnalogValue); 619 Serial.print(" "); 620 Serial.println(rightAnalogValue); 621 622 #endif 623 624 // map values 625 leftValue = map(leftAnalogValue * sensitivityFactor, 626 minValue, maxValue, 0, maxDisplaySegments); 627 rightValue = map(rightAnalogValue 628 * sensitivityFactor, minValue, maxValue, 0, maxDisplaySegments); 629 630 if (leftValue 631 > maxDisplaySegments) { 632 leftValue = maxDisplaySegments; 633 drawOverflow(); 634 635 } 636 637 if (rightValue > maxDisplaySegments) { 638 rightValue = maxDisplaySegments; 639 640 drawOverflow(); 641 } 642} 643 644void storePrevValues() { 645 prevLeftAnalogValue 646 = leftAnalogValue; 647 prevRightAnalogValue = rightAnalogValue; 648 649 prevLeftValue 650 = leftValue; 651 prevRightValue = rightValue; 652} 653 654void getPeaks() { 655 656 if (leftValue > leftPeak) { 657 leftPeak = leftValue; 658 leftPeakTime = 659 0; 660 leftFirstPeak = true; 661 662 if (bouncingPeaks) { 663 leftPeakBouncing 664 = true; 665 leftPeakBounceCounter = 0; 666 leftPeakBounceDelayCounter 667 = 0; 668 } 669 } 670 else { 671 leftPeakTime++; 672 if (droppingPeak) 673 { 674 if (leftFirstPeak) { 675 if (leftPeakTime > peakTimeFirstDropDelay) 676 { 677 clearLeftPeak(); 678 leftFirstPeak = false; 679 } 680 681 } 682 else { 683 if (leftPeakTime > peakTimeDropDelay) { 684 clearLeftPeak(); 685 686 } 687 } 688 } 689 else { 690 if (leftPeakTime > peakTimeNoDropDelay) 691 { 692 clearLeftPeak(); 693 } 694 } 695 } 696 697 if (leftPeakBouncing) 698 { 699 if (leftFirstPeak) { 700 leftPeakBounceDelayCounter++; 701 if 702 (leftPeakBounceDelayCounter >= bouncingPeakDelay) { 703 leftPeakBounceDelayCounter 704 = 0; 705 leftPeakBounceCounter += bouncingPeakCounterInc; 706 707 if 708 (leftPeakBounceCounter >= 180) { 709 clearLeftBouncePeak(); 710 clearLeftBounce(); 711 712 } 713 else { 714 leftPeakBounce = min((sin(leftPeakBounceCounter 715 * 0.0174532925) * bouncingPeaksNumOfLeds), (maxDisplaySegments - leftPeak)); 716 717 if (leftPeakBounce != prevLeftPeakBounce) { 718 clearLeftBouncePeak(); 719 720 } 721 prevLeftPeakBounce = leftPeakBounce; 722 } 723 } 724 725 } 726 } 727 728 if (rightValue > rightPeak) { 729 rightPeak = rightValue; 730 731 rightPeakTime = 0; 732 rightFirstPeak = true; 733 734 if (bouncingPeaks) 735 { 736 rightPeakBouncing = true; 737 rightPeakBounceCounter = 0; 738 rightPeakBounceDelayCounter 739 = 0; 740 } 741 } 742 else { 743 rightPeakTime++; 744 if (droppingPeak) 745 { 746 if (rightFirstPeak) { 747 if (rightPeakTime > peakTimeFirstDropDelay) 748 { 749 clearRightPeak(); 750 rightFirstPeak = false; 751 } 752 753 } 754 else { 755 if (rightPeakTime > peakTimeDropDelay) 756 clearRightPeak(); 757 758 } 759 } 760 else { 761 if (rightPeakTime > peakTimeNoDropDelay) 762 763 clearRightPeak(); 764 } 765 } 766 767 if (rightPeakBouncing) { 768 769 if (rightFirstPeak) { 770 rightPeakBounceDelayCounter++; 771 if (rightPeakBounceDelayCounter 772 >= bouncingPeakDelay) { 773 rightPeakBounceDelayCounter = 0; 774 rightPeakBounceCounter 775 += bouncingPeakCounterInc; 776 777 if (rightPeakBounceCounter >= 180) { 778 779 clearRightBouncePeak(); 780 clearRightBounce(); 781 } 782 783 else { 784 rightPeakBounce = min((sin(rightPeakBounceCounter 785 * 0.0174532925) * bouncingPeaksNumOfLeds), (maxDisplaySegments - rightPeak)); 786 787 if (rightPeakBounce != prevRightPeakBounce) { 788 clearRightBouncePeak(); 789 790 } 791 prevRightPeakBounce = rightPeakBounce; 792 } 793 794 } 795 } 796 } 797} 798 799void drawValues() { 800 if (splitStrip) { 801 802 for (i = middleOffset; i < leftValue; i++) 803 strip.setPixelColor(i, stripColor[i]); 804 805 806 for (i = prevLeftValue; i > leftValue; i--) 807 strip.setPixelColor(i, 808 0); 809 810 for (i = middleOffset; i < rightValue; i++) 811 strip.setPixelColor(stripMiddle 812 + i, stripColor[i]); 813 814 for (i = prevRightValue; i > rightValue; i--) 815 816 strip.setPixelColor(stripMiddle + i, 0); 817 } 818 else { 819 for (i 820 = middleOffset; i < leftValue; i++) 821 strip.setPixelColor(stripMiddle + i, 822 stripColor[i]); 823 824 for (i = prevLeftValue; i > leftValue; i--) 825 strip.setPixelColor(stripMiddle 826 + i, 0); 827 828 for (i = middleOffset; i < rightValue; i++) 829 strip.setPixelColor(stripMiddle 830 - i, stripColor[i]); 831 832 for (i = prevRightValue; i > rightValue; i--) 833 834 strip.setPixelColor(stripMiddle - i, 0); 835 } 836 837 if (displayMiddleLed) 838 strip.setPixelColor(stripMiddle, stripMiddleColor); 839 strip.show(); 840} 841 842void 843 drawPeaks() { 844 if (leftPeak > 0) { 845 if (droppingPeakFade && leftPeakBouncing 846 == false) 847 stripHoldColor = strip.Color(max(1, (255 * leftPeak * ledFactor_div_numOfSegments)), 848 0, 0); 849 else 850 stripHoldColor = stripColor[numOfSegments]; 851 852 853 if (splitStrip) 854 strip.setPixelColor((leftPeak + leftPeakBounce), stripHoldColor); 855 856 else 857 strip.setPixelColor(stripMiddle + (leftPeak + leftPeakBounce), 858 stripHoldColor); 859 } 860 861 if (rightPeak > 0) { 862 if (droppingPeakFade 863 && rightPeakBouncing == false) 864 stripHoldColor = strip.Color(max(1, (255 865 * rightPeak * ledFactor_div_numOfSegments)), 0, 0); 866 else 867 stripHoldColor 868 = stripColor[numOfSegments]; 869 870 if (splitStrip) 871 strip.setPixelColor(stripMiddle 872 + rightPeak + prevRightPeakBounce, stripHoldColor); 873 else 874 strip.setPixelColor(stripMiddle 875 - (rightPeak + prevRightPeakBounce), stripHoldColor); 876 } 877 878 if (leftPeak 879 > 0 || rightPeak > 0) 880 strip.show(); 881} 882 883void clearLeftPeak() 884 { 885 if (splitStrip) 886 strip.setPixelColor((leftPeak + prevLeftPeakBounce), 887 0); 888 else 889 strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 890 0); 891 892 if (droppingPeak) 893 leftPeak = leftPeak * peakDropFactor; 894 895 else 896 leftPeak = 0; 897 leftPeakTime = 0; 898} 899 900void clearLeftBounce() 901 { 902 leftPeakBouncing = false; 903 leftPeakBounceCounter = 0; 904 leftPeakBounce 905 = 0; 906 prevLeftPeakBounce = 0; 907} 908 909void clearLeftBouncePeak() { 910 if 911 (splitStrip) 912 strip.setPixelColor((leftPeak + prevLeftPeakBounce), 0); 913 914 else 915 strip.setPixelColor(stripMiddle + (leftPeak + prevLeftPeakBounce), 916 0); 917} 918 919void clearRightPeak() { 920 if (splitStrip) 921 strip.setPixelColor(stripMiddle 922 + rightPeak + prevRightPeakBounce, 0); 923 else 924 strip.setPixelColor(stripMiddle 925 - (rightPeak + prevRightPeakBounce), 0); 926 927 if (droppingPeak) 928 rightPeak 929 = rightPeak * peakDropFactor; 930 else 931 rightPeak = 0; 932 rightPeakTime 933 = 0; 934} 935 936void clearRightBounce() { 937 rightPeakBouncing = false; 938 rightPeakBounceCounter 939 = 0; 940 rightPeakBounce = 0; 941 prevRightPeakBounce = 0; 942} 943 944void clearRightBouncePeak() 945 { 946 if (splitStrip) 947 strip.setPixelColor((stripMiddle + rightPeak + prevRightPeakBounce), 948 0); 949 else 950 strip.setPixelColor(stripMiddle - (rightPeak + prevRightPeakBounce), 951 0); 952} 953 954void drawOverflow() { 955 for (i = 0; i <= numOfSegments; i++) 956 { 957 strip.setPixelColor(stripMiddle + i, stripOverflowColor); 958 strip.setPixelColor(stripMiddle 959 - i, stripOverflowColor); 960 } 961 strip.show(); 962 delay(overflowDelay); 963 964 965 for (i = 0; i <= numOfSegments; i++) { 966 strip.setPixelColor(stripMiddle 967 + i, 0); 968 strip.setPixelColor(stripMiddle - i, 0); 969 } 970 strip.show(); 971} 972 973void 974 setStripColors() { 975 int orangeLimit; 976 ledFactor = (float)ledBrightness / 977 255; 978 979 float orangeFactor = orangeLimitAmount / halfNumOfSegments; 980 ledFactor_div_numOfSegments 981 = ledFactor / numOfSegments; 982 983 stripOverflowColor = strip.Color(min(255, 984 255 * ledFactor * 1.5), 0, 0); 985 stripMiddleColor = strip.Color(0, 0, 255 * ledFactor); 986 987 988 stripColor[0] = strip.Color(0, 255 * ledFactor, 0); 989 for (i = 1; i <= numOfSegments; 990 i++) { 991 if (i <= halfNumOfSegments) 992 orangeLimit = (i * orangeFactor); 993 994 else 995 orangeLimit = ((numOfSegments - i) * orangeFactor); 996 997 stripColor[i] 998 = strip.Color((255 * i * ledFactor_div_numOfSegments), ((255 - orangeLimit) * (numOfSegments 999 - i) * ledFactor_div_numOfSegments), 0); 1000 } 1001 1002 stripHoldColor = stripColor[numOfSegments]; 1003} 1004 1005void 1006 startupAnimation() { 1007 for (j = 0; j < 2; j++) { 1008 for (i = 0; i <= numOfSegments; 1009 i++) { 1010 strip.setPixelColor(stripMiddle - i, stripColor[i]); 1011 strip.setPixelColor(stripMiddle 1012 + i, stripColor[i]); 1013 strip.show(); 1014 delay(startupAnimationDelay); 1015 1016 } 1017 1018 for (i = 0; i <= numOfSegments; i++) { 1019 strip.setPixelColor(stripMiddle 1020 + i, 0); 1021 strip.setPixelColor(stripMiddle - i, 0); 1022 strip.show(); 1023 1024 delay(startupAnimationDelay); 1025 } 1026 } 1027} 1028
Downloadable files
untitled
untitled
SCHEMATICS
SCHEMATICS
untitled
untitled
SCHEMATICS
SCHEMATICS
untitled
untitled
Comments
Only logged in users can leave comments
Anonymous user
2 years ago
Hello, I would like to do this project but I don't have an Arduino Nano R3 (ATMEGA328). But I do have an Arduino UNO (ATmega328P). I was wondering if there is any problem if I use UNO in this project, because i see that the microcontroller is the same but with a "P" extra. Thank you.
TheTNR
2 years ago
Hi Carlos Iglesias, dont worry. You can use all kind of arduino series. It will be work correctly... Have a good day...
Anonymous user
2 years ago
Hello, I was wondering how to make program with WS2812B RGB instead of original. Any suggestions?
Technogama
5 years ago
Hello, I was wondering how to make program with WS2812B RGB instead of original. Any suggestions?
Anonymous user
6 years ago
hello good afternoon, I wonder if you could send me the design of the circle to print in 3D. please contact me email: romancasas2002@gmail.com
TheTNR
2 years ago
Hi romancasas44, we have changed link. Please check video description and you will find... Thanks
Anonymous user
7 years ago
Hello, I would like to do this project but I don't have an Arduino Nano R3 (ATMEGA328). But I do have an Arduino UNO (ATmega328P). I was wondering if there is any problem if I use UNO in this project, because i see that the microcontroller is the same but with a "P" extra. Thank you.
TheTNR
2 years ago
Hi Carlos Iglesias, dont worry. You can use all kind of arduino series. It will be work correctly... Have a good day...
anacarol087
2 years ago
ola bom dia eu gostaria de seber se da PARA Subistituir o arduino nano R3 por outro como o arduino 33 IoT , se o projeto funcionaria normal ou ate melhor ?