Witam! Chciałbym przedstawić wykonany prze zemnie VU metr. przeglądając różne konstrukcje na YT postanowiłem złożyć w większej wersji takowy audiowizualny gadżet. VU metr ma wysokość ok 376mm i średnice 150mm. Dyski (26szt) wykonane zostały na laserze z przeźroczystej pleksy 5mm. W celu uzyskania lepszego wizualnego efektu przeszlifowałem krawędzie. Każdy dysk jest oddzielony aluminiową podkładką 35mm x 16mm x 8mm. Podstawa i górny dekielek również wykonany z aluminium na obrabiarce CNC. Diody LED zastosowane w konstrukcji to taśmaWS2812b (74diody/m ), które są przyklejone do rdzenia całej wieży wykonanego z półwałka aluminium o średnicy 16mm. Całością steruje Andurino Nano, program zaczerpnięty został z podobnego projektu i przystosowany do obsługi 26 diod LED. Program obsługuje wyjście linowe, po odpowiedniej modyfikacji programu można przerobić na mikrofon. VU metr posiada 16 trybów wyświetlania w tym tryb automatyczny, które przełączamy wciskając przycisk. Całość zasilana z ładowarki od smartfona 5V 2A,
Wykaz części (zakupione u majfrendów):
– Andurino nano 1 szt 7zł
– Gniazdo DC 1szt 0.2zł
– Gniazdo mono jack 3.5 1szt 0.2zł
– 0.5m taśmy LED WS2812b 77Led/1m -18zł (wykorzystano 26 szt)
– Przycisk Switch 1szt
-Przełącznik hebelkowy 1szt 0.20zł
– Podstawa + półwałek+dekielek + dystanse wykonane u mnie w zakładzie pracy
– Krążki wycięte na laserze 26szt 150zł
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 |
#include <Adafruit_NeoPixel.h> #include <FastLED.h> #include <math.h> #include <SoftwareSerial.h> #define N_PIXELS 26 // Number of pixels in strand #define N_PIXELS_HALF (N_PIXELS/2) #define MIC_PIN A5 // Microphone is attached to this analog pin #define LED_PIN 6 // NeoPixel LED strand is connected to this pin #define SAMPLE_WINDOW 10 // Sample window for average level #define PEAK_HANG 24 //Time of pause before peak dot falls #define PEAK_FALL 20 //Rate of falling peak dot #define PEAK_FALL2 8 //Rate of falling peak dot #define INPUT_FLOOR 10 //Lower range of analogRead input #define INPUT_CEILING 300 //Max range of analogRead input, the lower the value the more sensitive (1023 = max)300 (150) #define DC_OFFSET 0 // DC offset in mic signal - if unusure, leave 0 #define NOISE 10 // Noise/hum/interference in mic signal #define SAMPLES 60 // Length of buffer for dynamic level adjustment #define TOP (N_PIXELS + 2) // Allow dot to go slightly off scale #define SPEED .20 // Amount to increment RGB color by each cycle #define TOP2 (N_PIXELS + 1) // Allow dot to go slightly off scale #define LAST_PIXEL_OFFSET N_PIXELS-1 #define PEAK_FALL_MILLIS 10 // Rate of peak falling dot #define POT_PIN 4 #define BG 0 #define LAST_PIXEL_OFFSET N_PIXELS-1 #if FASTLED_VERSION < 3001000 #error "Requires FastLED 3.1 or later; check github for latest code." #endif #define BRIGHTNESS 255 #define LED_TYPE WS2812B // Only use the LED_PIN for WS2812's #define COLOR_ORDER GRB #define COLOR_MIN 0 #define COLOR_MAX 255 #define DRAW_MAX 100 #define SEGMENTS 4 // Number of segments to carve amplitude bar into #define COLOR_WAIT_CYCLES 10 // Loop cycles to wait between advancing pixel origin #define qsubd(x, b) ((x>b)?b:0) #define qsuba(x, b) ((x>b)?x-b:0) // Analog Unsigned subtraction macro. if result <0, then => 0. By Andrew Tuline. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) struct CRGB leds[N_PIXELS]; Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800); static uint16_t dist; // A random number for noise generator. uint16_t scale = 30; // Wouldn't recommend changing this on the fly, or the animation will be really blocky. uint8_t maxChanges = 48; // Value for blending between palettes. CRGBPalette16 currentPalette(OceanColors_p); CRGBPalette16 targetPalette(CloudColors_p); //new ripple vu uint8_t timeval = 20; // Currently 'delay' value. No, I don't use delays, I use EVERY_N_MILLIS_I instead. uint16_t loops = 0; // Our loops per second counter. bool samplepeak = 0; // This sample is well above the average, and is a 'peak'. uint16_t oldsample = 0; // Previous sample is used for peak detection and for 'on the fly' values. bool thisdir = 0; //new ripple vu // Modes enum { } MODE; bool reverse = true; int BRIGHTNESS_MAX = 80; int brightness = 20; byte // peak = 0, // Used for falling dot // dotCount = 0, // Frame counter for delaying dot-falling speed volCount = 0; // Frame counter for storing past volume data int reading, vol[SAMPLES], // Collection of prior volume samples lvl = 10, // Current "dampened" audio level minLvlAvg = 0, // For dynamic adjustment of graph low & high maxLvlAvg = 512; float greenOffset = 30, blueOffset = 150; // cycle variables int CYCLE_MIN_MILLIS = 2; int CYCLE_MAX_MILLIS = 1000; int cycleMillis = 20; bool paused = false; long lastTime = 0; bool boring = true; bool gReverseDirection = false; int myhue = 0; //vu ripple uint8_t colour; uint8_t myfade = 255; // Starting brightness. #define maxsteps 16 // Case statement wouldn't allow a variable. int peakspersec = 0; int peakcount = 0; uint8_t bgcol = 0; int thisdelay = 20; uint8_t max_bright = 255; unsigned int sample; //Samples #define NSAMPLES 64 unsigned int samplearray[NSAMPLES]; unsigned long samplesum = 0; unsigned int sampleavg = 0; int samplecount = 0; //unsigned int sample = 0; unsigned long oldtime = 0; unsigned long newtime = 0; //Ripple variables int color; int center = 0; int step = -1; int maxSteps = 16; float fadeRate = 0.80; int diff; //vu 8 variables int origin = 0, color_wait_count = 0, scroll_color = COLOR_MIN, last_intensity = 0, intensity_max = 0, origin_at_flip = 0; uint32_t draw[DRAW_MAX]; boolean growing = false, fall_from_left = true; //background color uint32_t currentBg = random(256); uint32_t nextBg = currentBg; TBlendType currentBlending; const int buttonPin = 0; // the number of the pushbutton pin //Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; byte peak = 16; // Peak level of column; used for falling dots // unsigned int sample; byte dotCount = 0; //Frame counter for peak dot byte dotHangCount = 0; //Frame counter for holding peak dot void setup() { //analogReference(EXTERNAL); pinMode(buttonPin, INPUT); //initialize the buttonPin as output digitalWrite(buttonPin, HIGH); // Serial.begin(9600); strip.begin(); strip.show(); // all pixels to 'off' Serial.begin(57600); delay(3000); LEDS.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds,N_PIXELS).setCorrection(TypicalLEDStrip); LEDS.setBrightness(BRIGHTNESS); dist = random16(12345); // A semi-random number for our noise generator } float fscale( float originalMin, float originalMax, float newBegin, float newEnd, float inputValue, float curve){ float OriginalRange = 0; float NewRange = 0; float zeroRefCurVal = 0; float normalizedCurVal = 0; float rangedValue = 0; boolean invFlag = 0; // condition curve parameter // limit range if (curve > 10) curve = 10; if (curve < -10) curve = -10; curve = (curve * -.1) ; // - invert and scale - this seems more intuitive - postive numbers give more weight to high end on output curve = pow(10, curve); // convert linear scale into lograthimic exponent for other pow function // Check for out of range inputValues if (inputValue < originalMin) { inputValue = originalMin; } if (inputValue > originalMax) { inputValue = originalMax; } // Zero Refference the values OriginalRange = originalMax - originalMin; if (newEnd > newBegin){ NewRange = newEnd - newBegin; } else { NewRange = newBegin - newEnd; invFlag = 1; } zeroRefCurVal = inputValue - originalMin; normalizedCurVal = zeroRefCurVal / OriginalRange; // normalize to 0 - 1 float // Check for originalMin > originalMax - the math for all other cases i.e. negative numbers seems to work out fine if (originalMin > originalMax ) { return 0; } if (invFlag == 0){ rangedValue = (pow(normalizedCurVal, curve) * NewRange) + newBegin; } else // invert the ranges { rangedValue = newBegin - (pow(normalizedCurVal, curve) * NewRange); } return rangedValue; } void loop() { //for mic uint8_t i; uint16_t minLvl, maxLvl; int n, height; // end mic // read the pushbutton input pin: buttonState = digitalRead(buttonPin); // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; Serial.println("on"); Serial.print("number of button pushes: "); Serial.println(buttonPushCounter); if(buttonPushCounter==16) { buttonPushCounter=1;} } else { // if the current state is LOW then the button // wend from on to off: Serial.println("off"); } } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; switch (buttonPushCounter){ case 1: buttonPushCounter==1; { All2(); // NORMAL break;} case 2: buttonPushCounter==2; { vu(); // NORMAL break;} case 3: buttonPushCounter==3; { vu1(); // Centre out break;} case 4: buttonPushCounter==4; { vu2(); // Centre Inwards break;} case 5: buttonPushCounter==5; { Vu3(); // Normal Rainbow break;} case 6: buttonPushCounter==6; { Vu4(); // Centre rainbow break;} case 7: buttonPushCounter==7; { Vu5(); // Shooting Star break;} case 8: buttonPushCounter==8; { Vu6(); // Falling star break;} case 9: buttonPushCounter==9; { vu7(); // Ripple with background break;} case 10: buttonPushCounter==10; { vu8(); // Shatter break;} case 11: buttonPushCounter==11; { vu9(); // Pulse break;} case 12: buttonPushCounter==12; { vu10(); // stream break;} case 13: buttonPushCounter==13; { vu11(); // Ripple without Background break;} case 14: buttonPushCounter==14; { vu12(); // Ripple without Background break;} case 15: buttonPushCounter==15; { vu13(); // Ripple without Background break;} case 16: buttonPushCounter==16; { colorWipe(strip.Color(0, 0, 0), 10); // Black break;} } } void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); if (digitalRead(buttonPin) != lastButtonState) // <------------- add this return; // <------------ and this delay(wait); }} void vu() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if(height < 0L) height = 0; // Clip output else if(height > TOP) height = TOP; if(height > peak) peak = height; // Keep 'peak' dot at top // Color pixels based on rainbow gradient for(i=0; i<N_PIXELS; i++) { if(i >= height) strip.setPixelColor(i, 0, 0, 0); else strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150))); } // Draw peak dot if(peak > 0 && peak <= N_PIXELS-1) strip.setPixelColor(peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); strip.show(); // Update strip // Every few frames, make the peak pixel drop by 1: if(++dotCount >= PEAK_FALL) { //fall rate if(peak > 0) peak--; dotCount = 0; } vol[volCount] = n; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } // Input a value 0 to 255 to get a color value. // The colors are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { if(WheelPos < 85) { return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } else if(WheelPos < 170) { WheelPos -= 85; return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else { WheelPos -= 170; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } } void vu1() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if(height < 0L) height = 0; // Clip output else if(height > TOP) height = TOP; if(height > peak) peak = height; // Keep 'peak' dot at top // Color pixels based on rainbow gradient for(i=0; i<N_PIXELS_HALF; i++) { if(i >= height) { strip.setPixelColor(N_PIXELS_HALF-i-1, 0, 0, 0); strip.setPixelColor(N_PIXELS_HALF+i, 0, 0, 0); } else { uint32_t color = Wheel(map(i,0,N_PIXELS_HALF-1,30,150)); strip.setPixelColor(N_PIXELS_HALF-i-1,color); strip.setPixelColor(N_PIXELS_HALF+i,color); } } // Draw peak dot if(peak > 0 && peak <= N_PIXELS_HALF-1) { uint32_t color = Wheel(map(peak,0,N_PIXELS_HALF-1,30,150)); strip.setPixelColor(N_PIXELS_HALF-peak-1,color); strip.setPixelColor(N_PIXELS_HALF+peak,color); } strip.show(); // Update strip // Every few frames, make the peak pixel drop by 1: if(++dotCount >= PEAK_FALL) { //fall rate if(peak > 0) peak--; dotCount = 0; } vol[volCount] = n; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void vu2() { unsigned long startMillis= millis(); // Start of sample window float peakToPeak = 0; // peak-to-peak level unsigned int signalMax = 0; unsigned int signalMin = 1023; unsigned int c, y; while (millis() - startMillis < SAMPLE_WINDOW) { sample = analogRead(MIC_PIN); if (sample < 1024) { if (sample > signalMax) { signalMax = sample; } else if (sample < signalMin) { signalMin = sample; } } } peakToPeak = signalMax - signalMin; // Serial.println(peakToPeak); for (int i=0;i<=N_PIXELS_HALF-1;i++){ uint32_t color = Wheel(map(i,0,N_PIXELS_HALF-1,30,150)); strip.setPixelColor(N_PIXELS-i,color); strip.setPixelColor(0+i,color); } c = fscale(INPUT_FLOOR, INPUT_CEILING, N_PIXELS_HALF, 0, peakToPeak, 2); if(c < peak) { peak = c; // Keep dot on top dotHangCount = 0; // make the dot hang before falling } if (c <= strip.numPixels()) { // Fill partial column with off pixels drawLine(N_PIXELS_HALF, N_PIXELS_HALF-c, strip.Color(0, 0, 0)); drawLine(N_PIXELS_HALF, N_PIXELS_HALF+c, strip.Color(0, 0, 0)); } y = N_PIXELS_HALF - peak; uint32_t color1 = Wheel(map(y,0,N_PIXELS_HALF-1,30,150)); strip.setPixelColor(y-1,color1); //strip.setPixelColor(y-1,Wheel(map(y,0,N_PIXELS_HALF-1,30,150))); y = N_PIXELS_HALF + peak; strip.setPixelColor(y,color1); //strip.setPixelColor(y+1,Wheel(map(y,0,N_PIXELS_HALF+1,30,150))); strip.show(); // Frame based peak dot animation if(dotHangCount > PEAK_HANG) { //Peak pause length if(++dotCount >= PEAK_FALL2) { //Fall rate peak++; dotCount = 0; } } else { dotHangCount++; } } void Vu3() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if (height < 0L) height = 0; // Clip output else if (height > TOP) height = TOP; if (height > peak) peak = height; // Keep 'peak' dot at top greenOffset += SPEED; blueOffset += SPEED; if (greenOffset >= 255) greenOffset = 0; if (blueOffset >= 255) blueOffset = 0; // Color pixels based on rainbow gradient for (i = 0; i < N_PIXELS; i++) { if (i >= height) { strip.setPixelColor(i, 0, 0, 0); } else { strip.setPixelColor(i, Wheel( map(i, 0, strip.numPixels() - 1, (int)greenOffset, (int)blueOffset) )); } } // Draw peak dot if(peak > 0 && peak <= N_PIXELS-1) strip.setPixelColor(peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); strip.show(); // Update strip // Every few frames, make the peak pixel drop by 1: if(++dotCount >= PEAK_FALL) { //fall rate if(peak > 0) peak--; dotCount = 0; } strip.show(); // Update strip vol[volCount] = n; if (++volCount >= SAMPLES) { volCount = 0; } // Get volume range of prior frames minLvl = maxLvl = vol[0]; for (i = 1; i < SAMPLES; i++) { if (vol[i] < minLvl) { minLvl = vol[i]; } else if (vol[i] > maxLvl) { maxLvl = vol[i]; } } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if ((maxLvl - minLvl) < TOP) { maxLvl = minLvl + TOP; } minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void Vu4() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if(height < 0L) height = 0; // Clip output else if(height > TOP) height = TOP; if(height > peak) peak = height; // Keep 'peak' dot at top greenOffset += SPEED; blueOffset += SPEED; if (greenOffset >= 255) greenOffset = 0; if (blueOffset >= 255) blueOffset = 0; // Color pixels based on rainbow gradient for(i=0; i<N_PIXELS_HALF; i++) { if(i >= height) { strip.setPixelColor(N_PIXELS_HALF-i-1, 0, 0, 0); strip.setPixelColor(N_PIXELS_HALF+i, 0, 0, 0); } else { uint32_t color = Wheel(map(i,0,N_PIXELS_HALF-1,(int)greenOffset, (int)blueOffset)); strip.setPixelColor(N_PIXELS_HALF-i-1,color); strip.setPixelColor(N_PIXELS_HALF+i,color); } } // Draw peak dot if(peak > 0 && peak <= N_PIXELS_HALF-1) { uint32_t color = Wheel(map(peak,0,N_PIXELS_HALF-1,30,150)); strip.setPixelColor(N_PIXELS_HALF-peak-1,color); strip.setPixelColor(N_PIXELS_HALF+peak,color); } strip.show(); // Update strip // Every few frames, make the peak pixel drop by 1: if(++dotCount >= PEAK_FALL) { //fall rate if(peak > 0) peak--; dotCount = 0; } vol[volCount] = n; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < TOP) maxLvl = minLvl + TOP; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void Vu5() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP2 * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if(height < 0L) height = 0; // Clip output else if(height > TOP2) height = TOP2; if(height > peak) peak = height; // Keep 'peak' dot at top #ifdef CENTERED // Color pixels based on rainbow gradient for(i=0; i<(N_PIXELS/2); i++) { if(((N_PIXELS/2)+i) >= height) { strip.setPixelColor(((N_PIXELS/2) + i), 0, 0, 0); strip.setPixelColor(((N_PIXELS/2) - i), 0, 0, 0); } else { strip.setPixelColor(((N_PIXELS/2) + i),Wheel(map(((N_PIXELS/2) + i),0,strip.numPixels()-1,30,150))); strip.setPixelColor(((N_PIXELS/2) - i),Wheel(map(((N_PIXELS/2) - i),0,strip.numPixels()-1,30,150))); } } // Draw peak dot if(peak > 0 && peak <= LAST_PIXEL_OFFSET) { strip.setPixelColor(((N_PIXELS/2) + peak),255,255,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); strip.setPixelColor(((N_PIXELS/2) - peak),255,255,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); } #else // Color pixels based on rainbow gradient for(i=0; i<N_PIXELS; i++) { if(i >= height) { strip.setPixelColor(i, 0, 0, 0); } else { strip.setPixelColor(i,Wheel(map(i,0,strip.numPixels()-1,30,150))); } } // Draw peak dot if(peak > 0 && peak <= LAST_PIXEL_OFFSET) { strip.setPixelColor(peak,255,255,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); } #endif // Every few frames, make the peak pixel drop by 1: if (millis() - lastTime >= PEAK_FALL_MILLIS) { lastTime = millis(); strip.show(); // Update strip //fall rate if(peak > 0) peak--; } vol[volCount] = n; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < TOP2) maxLvl = minLvl + TOP2; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void Vu6() { uint8_t i; uint16_t minLvl, maxLvl; int n, height; n = analogRead(MIC_PIN); // Raw reading from mic n = abs(n - 512 - DC_OFFSET); // Center on zero n = (n <= NOISE) ? 0 : (n - NOISE); // Remove noise/hum lvl = ((lvl * 7) + n) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): height = TOP2 * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); if(height < 0L) height = 0; // Clip output else if(height > TOP2) height = TOP2; if(height > peak) peak = height; // Keep 'peak' dot at top #ifdef CENTERED // Draw peak dot if(peak > 0 && peak <= LAST_PIXEL_OFFSET) { strip.setPixelColor(((N_PIXELS/2) + peak),255,255,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); strip.setPixelColor(((N_PIXELS/2) - peak),255,255,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); } #else // Color pixels based on rainbow gradient for(i=0; i<N_PIXELS; i++) { if(i >= height) { strip.setPixelColor(i, 0, 0, 0); } else { } } // Draw peak dot if(peak > 0 && peak <= LAST_PIXEL_OFFSET) { strip.setPixelColor(peak,0,0,255); // (peak,Wheel(map(peak,0,strip.numPixels()-1,30,150))); } #endif // Every few frames, make the peak pixel drop by 1: if (millis() - lastTime >= PEAK_FALL_MILLIS) { lastTime = millis(); strip.show(); // Update strip //fall rate if(peak > 0) peak--; } vol[volCount] = n; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < TOP2) maxLvl = minLvl + TOP2; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void vu7() { EVERY_N_MILLISECONDS(1000) { peakspersec = peakcount; // Count the peaks per second. This value will become the foreground hue. peakcount = 0; // Reset the counter every second. } soundmems(); EVERY_N_MILLISECONDS(20) { ripple3(); } show_at_max_brightness_for_power(); } // loop() void soundmems() { // Rolling average counter - means we don't have to go through an array each time. newtime = millis(); int tmp = analogRead(MIC_PIN) - 512; sample = abs(tmp); int potin = map(analogRead(POT_PIN), 0, 1023, 0, 60); samplesum = samplesum + sample - samplearray[samplecount]; // Add the new sample and remove the oldest sample in the array sampleavg = samplesum / NSAMPLES; // Get an average samplearray[samplecount] = sample; // Update oldest sample in the array with new sample samplecount = (samplecount + 1) % NSAMPLES; // Update the counter for the array if (newtime > (oldtime + 200)) digitalWrite(13, LOW); // Turn the LED off 200ms after the last peak. if ((sample > (sampleavg + potin)) && (newtime > (oldtime + 60)) ) { // Check for a peak, which is 30 > the average, but wait at least 60ms for another. step = -1; peakcount++; digitalWrite(13, HIGH); oldtime = newtime; } } // soundmems() void ripple3() { for (int i = 0; i < N_PIXELS; i++) leds[i] = CHSV(bgcol, 255, sampleavg*2); // Set the background colour. switch (step) { case -1: // Initialize ripple variables. center = random(N_PIXELS); colour = (peakspersec*10) % 255; // More peaks/s = higher the hue colour. step = 0; bgcol = bgcol+8; break; case 0: leds[center] = CHSV(colour, 255, 255); // Display the first pixel of the ripple. step ++; break; case maxsteps: // At the end of the ripples. // step = -1; break; default: // Middle of the ripples. leds[(center + step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); // Simple wrap from Marc Miller. leds[(center - step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); step ++; // Next step. break; } // switch step } // ripple() void vu8() { int intensity = calculateIntensity(); updateOrigin(intensity); assignDrawValues(intensity); writeSegmented(); updateGlobals(); } int calculateIntensity() { int intensity; reading = analogRead(MIC_PIN); // Raw reading from mic reading = abs(reading - 512 - DC_OFFSET); // Center on zero reading = (reading <= NOISE) ? 0 : (reading - NOISE); // Remove noise/hum lvl = ((lvl * 7) + reading) >> 3; // "Dampened" reading (else looks twitchy) // Calculate bar height based on dynamic min/max levels (fixed point): intensity = DRAW_MAX * (lvl - minLvlAvg) / (long)(maxLvlAvg - minLvlAvg); return constrain(intensity, 0, DRAW_MAX-1); } void updateOrigin(int intensity) { // detect peak change and save origin at curve vertex if (growing && intensity < last_intensity) { growing = false; intensity_max = last_intensity; fall_from_left = !fall_from_left; origin_at_flip = origin; } else if (intensity > last_intensity) { growing = true; origin_at_flip = origin; } last_intensity = intensity; // adjust origin if falling if (!growing) { if (fall_from_left) { origin = origin_at_flip + ((intensity_max - intensity) / 2); } else { origin = origin_at_flip - ((intensity_max - intensity) / 2); } // correct for origin out of bounds if (origin < 0) { origin = DRAW_MAX - abs(origin); } else if (origin > DRAW_MAX - 1) { origin = origin - DRAW_MAX - 1; } } } void assignDrawValues(int intensity) { // draw amplitue as 1/2 intensity both directions from origin int min_lit = origin - (intensity / 2); int max_lit = origin + (intensity / 2); if (min_lit < 0) { min_lit = min_lit + DRAW_MAX; } if (max_lit >= DRAW_MAX) { max_lit = max_lit - DRAW_MAX; } for (int i=0; i < DRAW_MAX; i++) { // if i is within origin +/- 1/2 intensity if ( (min_lit < max_lit && min_lit < i && i < max_lit) // range is within bounds and i is within range || (min_lit > max_lit && (i > min_lit || i < max_lit)) // range wraps out of bounds and i is within that wrap ) { draw[i] = Wheel(scroll_color); } else { draw[i] = 0; } } } void writeSegmented() { int seg_len = N_PIXELS / SEGMENTS; for (int s = 0; s < SEGMENTS; s++) { for (int i = 0; i < seg_len; i++) { strip.setPixelColor(i + (s*seg_len), draw[map(i, 0, seg_len, 0, DRAW_MAX)]); } } strip.show(); } uint32_t * segmentAndResize(uint32_t* draw) { int seg_len = N_PIXELS / SEGMENTS; uint32_t segmented[N_PIXELS]; for (int s = 0; s < SEGMENTS; s++) { for (int i = 0; i < seg_len; i++) { segmented[i + (s * seg_len) ] = draw[map(i, 0, seg_len, 0, DRAW_MAX)]; } } return segmented; } void writeToStrip(uint32_t* draw) { for (int i = 0; i < N_PIXELS; i++) { strip.setPixelColor(i, draw[i]); } strip.show(); } void updateGlobals() { uint16_t minLvl, maxLvl; //advance color wheel color_wait_count++; if (color_wait_count > COLOR_WAIT_CYCLES) { color_wait_count = 0; scroll_color++; if (scroll_color > COLOR_MAX) { scroll_color = COLOR_MIN; } } vol[volCount] = reading; // Save sample for dynamic leveling if(++volCount >= SAMPLES) volCount = 0; // Advance/rollover sample counter // Get volume range of prior frames minLvl = maxLvl = vol[0]; for(uint8_t i=1; i<SAMPLES; i++) { if(vol[i] < minLvl) minLvl = vol[i]; else if(vol[i] > maxLvl) maxLvl = vol[i]; } // minLvl and maxLvl indicate the volume range over prior frames, used // for vertically scaling the output graph (so it looks interesting // regardless of volume level). If they're too close together though // (e.g. at very low volume levels) the graph becomes super coarse // and 'jumpy'...so keep some minimum distance between them (this // also lets the graph go to zero when no sound is playing): if((maxLvl - minLvl) < N_PIXELS) maxLvl = minLvl + N_PIXELS; minLvlAvg = (minLvlAvg * 63 + minLvl) >> 6; // Dampen min/max levels maxLvlAvg = (maxLvlAvg * 63 + maxLvl) >> 6; // (fake rolling average) } void vu9() { //currentBlending = LINEARBLEND; currentPalette = OceanColors_p; // Initial palette. currentBlending = LINEARBLEND; EVERY_N_SECONDS(5) { // Change the palette every 5 seconds. for (int i = 0; i < 16; i++) { targetPalette[i] = CHSV(random8(), 255, 255); } } EVERY_N_MILLISECONDS(100) { // AWESOME palette blending capability once they do change. uint8_t maxChanges = 24; nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); } EVERY_N_MILLIS_I(thistimer,20) { // For fun, let's make the animation have a variable rate. uint8_t timeval = beatsin8(10,20,50); // Use a sinewave for the line below. Could also use peak/beat detection. thistimer.setPeriod(timeval); // Allows you to change how often this routine runs. fadeToBlackBy(leds, N_PIXELS, 16); // 1 = slow, 255 = fast fade. Depending on the faderate, the LED's further away will fade out. sndwave(); soundble(); } FastLED.setBrightness(max_bright); FastLED.show(); } // loop() void soundble() { // Quick and dirty sampling of the microphone. int tmp = analogRead(MIC_PIN) - 512 - DC_OFFSET; sample = abs(tmp); } // soundmems() void sndwave() { leds[N_PIXELS/2] = ColorFromPalette(currentPalette, sample, sample*2, currentBlending); // Put the sample into the center for (int i = N_PIXELS - 1; i > N_PIXELS/2; i--) { //move to the left // Copy to the left, and let the fade do the rest. leds[i] = leds[i - 1]; } for (int i = 0; i < N_PIXELS/2; i++) { // move to the right // Copy to the right, and let the fade to the rest. leds[i] = leds[i + 1]; } addGlitter(sampleavg); } void vu10() { EVERY_N_SECONDS(5) { // Change the target palette to a random one every 5 seconds. static uint8_t baseC = random8(); // You can use this as a baseline colour if you want similar hues in the next line. for (int i = 0; i < 16; i++) { targetPalette[i] = CHSV(random8(), 255, 255); } } EVERY_N_MILLISECONDS(100) { uint8_t maxChanges = 24; nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // AWESOME palette blending capability. } EVERY_N_MILLISECONDS(thisdelay) { // FastLED based non-blocking delay to update/display the sequence. soundtun(); FastLED.setBrightness(max_bright); FastLED.show(); } } // loop() void soundtun() { int n; n = analogRead(MIC_PIN); // Raw reading from mic n = qsuba(abs(n-512), 10); // Center on zero and get rid of low level noise CRGB newcolour = ColorFromPalette(currentPalette, constrain(n,0,255), constrain(n,0,255), currentBlending); nblend(leds[0], newcolour, 128); for (int i = N_PIXELS-1; i>0; i--) { leds[i] = leds[i-1]; } } // soundmems() void vu11() { EVERY_N_MILLISECONDS(1000) { peakspersec = peakcount; // Count the peaks per second. This value will become the foreground hue. peakcount = 0; // Reset the counter every second. } soundrip(); EVERY_N_MILLISECONDS(20) { rippled(); } FastLED.show(); } // loop() void soundrip() { // Rolling average counter - means we don't have to go through an array each time. newtime = millis(); int tmp = analogRead(MIC_PIN) - 512; sample = abs(tmp); int potin = map(analogRead(POT_PIN), 0, 1023, 0, 60); samplesum = samplesum + sample - samplearray[samplecount]; // Add the new sample and remove the oldest sample in the array sampleavg = samplesum / NSAMPLES; // Get an average Serial.println(sampleavg); samplearray[samplecount] = sample; // Update oldest sample in the array with new sample samplecount = (samplecount + 1) % NSAMPLES; // Update the counter for the array if (newtime > (oldtime + 200)) digitalWrite(13, LOW); // Turn the LED off 200ms after the last peak. if ((sample > (sampleavg + potin)) && (newtime > (oldtime + 60)) ) { // Check for a peak, which is 30 > the average, but wait at least 60ms for another. step = -1; peakcount++; oldtime = newtime; } } // soundmems() void rippled() { fadeToBlackBy(leds, N_PIXELS, 64); // 8 bit, 1 = slow, 255 = fast switch (step) { case -1: // Initialize ripple variables. center = random(N_PIXELS); colour = (peakspersec*10) % 255; // More peaks/s = higher the hue colour. step = 0; break; case 0: leds[center] = CHSV(colour, 255, 255); // Display the first pixel of the ripple. step ++; break; case maxsteps: // At the end of the ripples. // step = -1; break; default: // Middle of the ripples. leds[(center + step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); // Simple wrap from Marc Miller. leds[(center - step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); step ++; // Next step. break; } // switch step } // ripple() //Used to draw a line between two points of a given color void drawLine(uint8_t from, uint8_t to, uint32_t c) { uint8_t fromTemp; if (from > to) { fromTemp = from; from = to; to = fromTemp; } for(int i=from; i<=to; i++){ strip.setPixelColor(i, c); } } void setPixel(int Pixel, byte red, byte green, byte blue) { strip.setPixelColor(Pixel, strip.Color(red, green, blue)); } void setAll(byte red, byte green, byte blue) { for(int i = 0; i < N_PIXELS; i++ ) { setPixel(i, red, green, blue); } strip.show(); } void vu12() { EVERY_N_MILLISECONDS(1000) { peakspersec = peakcount; // Count the peaks per second. This value will become the foreground hue. peakcount = 0; // Reset the counter every second. } soundripped(); EVERY_N_MILLISECONDS(20) { rippvu(); } FastLED.show(); } // loop() void soundripped() { // Rolling average counter - means we don't have to go through an array each time. newtime = millis(); int tmp = analogRead(MIC_PIN) - 512; sample = abs(tmp); int potin = map(analogRead(POT_PIN), 0, 1023, 0, 60); samplesum = samplesum + sample - samplearray[samplecount]; // Add the new sample and remove the oldest sample in the array sampleavg = samplesum / NSAMPLES; // Get an average Serial.println(sampleavg); samplearray[samplecount] = sample; // Update oldest sample in the array with new sample samplecount = (samplecount + 1) % NSAMPLES; // Update the counter for the array if (newtime > (oldtime + 200)) digitalWrite(13, LOW); // Turn the LED off 200ms after the last peak. if ((sample > (sampleavg + potin)) && (newtime > (oldtime + 60)) ) { // Check for a peak, which is 30 > the average, but wait at least 60ms for another. step = -1; peakcount++; oldtime = newtime; } } // soundmems() void rippvu() { // Display ripples triggered by peaks. fadeToBlackBy(leds, N_PIXELS, 64); // 8 bit, 1 = slow, 255 = fast switch (step) { case -1: // Initialize ripple variables. center = random(N_PIXELS); colour = (peakspersec*10) % 255; // More peaks/s = higher the hue colour. step = 0; break; case 0: leds[center] = CHSV(colour, 255, 255); // Display the first pixel of the ripple. step ++; break; case maxsteps: // At the end of the ripples. // step = -1; break; default: // Middle of the ripples. leds[(center + step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); // Simple wrap from Marc Miller. leds[(center - step + N_PIXELS) % N_PIXELS] += CHSV(colour, 255, myfade/step*2); step ++; // Next step. break; } // switch step addGlitter(sampleavg); } // ripple() void vu13() { // The >>>>>>>>>> L-O-O-P <<<<<<<<<<<<<<<<<<<<<<<<<<<< is buried here!!!11!1! EVERY_N_MILLISECONDS(1000) { peakspersec = peakcount; // Count the peaks per second. This value will become the foreground hue. peakcount = 0; // Reset the counter every second. } soundripper(); EVERY_N_MILLISECONDS(20) { jugglep(); } FastLED.show(); } // loop() void soundripper() { // Rolling average counter - means we don't have to go through an array each time. newtime = millis(); int tmp = analogRead(MIC_PIN) - 512; sample = abs(tmp); int potin = map(analogRead(POT_PIN), 0, 1023, 0, 60); samplesum = samplesum + sample - samplearray[samplecount]; // Add the new sample and remove the oldest sample in the array sampleavg = samplesum / NSAMPLES; // Get an average Serial.println(sampleavg); samplearray[samplecount] = sample; // Update oldest sample in the array with new sample samplecount = (samplecount + 1) % NSAMPLES; // Update the counter for the array if (newtime > (oldtime + 200)) digitalWrite(13, LOW); // Turn the LED off 200ms after the last peak. if ((sample > (sampleavg + potin)) && (newtime > (oldtime + 60)) ) { // Check for a peak, which is 30 > the average, but wait at least 60ms for another. step = -1; peakcount++; oldtime = newtime; // Change the current pattern function periodically. jugglep(); } } // loop() void jugglep() { // Use the juggle routine, but adjust the timebase based on sampleavg for some randomness. // Persistent local variables static uint8_t thishue=0; timeval = 40; // Our EVERY_N_MILLIS_I timer value. leds[0] = ColorFromPalette(currentPalette, thishue++, sampleavg, LINEARBLEND); for (int i = N_PIXELS-1; i >0 ; i-- ) leds[i] = leds[i-1]; addGlitter(sampleavg/2); // Add glitter based on sampleavg. By Andrew Tuline. } // matrix() // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos, float opacity) { if(WheelPos < 85) { return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0); } else if(WheelPos < 170) { WheelPos -= 85; return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity); } else { WheelPos -= 170; return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity); } } void addGlitter( fract8 chanceOfGlitter) { // Let's add some glitter, thanks to Mark if( random8() < chanceOfGlitter) { leds[random16(N_PIXELS)] += CRGB::White; } } // addGlitter() // List of patterns to cycle through. Each is defined as a separate function below. typedef void (*SimplePatternList[])(); SimplePatternList qPatterns = {vu, vu1, vu2, Vu3, Vu4, Vu5, Vu6, vu7, vu8, vu9, vu10, vu11, vu12, vu13}; uint8_t qCurrentPatternNumber = 0; // Index number of which pattern is current void nextPattern2() { // add one to the current pattern number, and wrap around at the end qCurrentPatternNumber = (qCurrentPatternNumber + 1) % ARRAY_SIZE( qPatterns); } void All2() [url=https://obrazki.elektroda.pl/6958297300_1551911377.jpg][img]https://obrazki.elektroda.pl/6958297300_1551911377_thumb.jpg[/img][/url] [url=https://obrazki.elektroda.pl/1392494900_1551911375.jpg][img]https://obrazki.elektroda.pl/1392494900_1551911375_thumb.jpg[/img][/url] [url=https://obrazki.elektroda.pl/6189230000_1551911377.jpg][img]https://obrazki.elektroda.pl/6189230000_1551911377_thumb.jpg[/img][/url] [url=https://obrazki.elektroda.pl/7827595500_1551911377.jpg][img]https://obrazki.elektroda.pl/7827595500_1551911377_thumb.jpg[/img][/url] [url=https://obrazki.elektroda.pl/4611080200_1551911380.jpg][img]https://obrazki.elektroda.pl/4611080200_1551911380_thumb.jpg[/img][/url] [url=https://obrazki.elektroda.pl/7524480100_1551911379.jpg][img]https://obrazki.elektroda.pl/7524480100_1551911379_thumb.jpg[/img][/url] { // Call the current pattern function once, updating the 'leds' array qPatterns[qCurrentPatternNumber](); EVERY_N_SECONDS( 30 ) { nextPattern2(); } // change patterns periodically } |
1 |
Schemat:
Fotki:
FILM :
https://drive.google.com/file/d/1tkA-B1sug8uCswuwdvXgW8YrNv0TCZ_d/view?usp=drivesdk]Link
Efekt niesamowity, przyznam szczerze że jeszcze nie widziałem takiego UV Metru, i po obejrzeniu filmiku jestem pod ogromnym wrażeniem . Spokojnie mógłby posłużyć za oświetlenie na niejednej domówce. Niestety wydaje mi się, że opis jest niekompletny – brak kodu źródłowego…
Brak kodu – brak oceny. A miała być piątka…
Rozumiem że ów koszmarek o nazwie “kod” nie jest Twojego autorstwa – dobrze że to zaznaczyłeś bo miałby jedynkę :):):)
Szczególnie mnie zastanawia o co autorowi chodziło w tym fragmencie:
switch (buttonPushCounter){
case 1:
buttonPushCounter==1; {
All2(); // NORMAL
break;}
Warunek “ile razy naciśnięty przycisk” jeżeli raz to uruchom ‘void All2()’
Co tu jest niezrozumiałe?
Fajny projekt, ale to cnc + laser, … sorry jak mam to odtworzyć :(
Ale to nie jest poprawna składnia.
Obstawiam, że chodzi o linijkę:
buttonPushCounter == 1;
Linijka ta jest zdecydowanie niepotrzebna. Klamry { } w tym wypadku też nie są potrzebne
dokładnie tak. podejrzewam że to pozostałości po ifie zgrabnie przerobionym na switcha ;)
Jako iż nie jestem programistą a jedyne co programuje to proste programy w C oraz w pracy PLC w drabince, to mimo głębszej analizy sam tego programu do końca nie rozumie :)
pociesz się tym, że ja jako zawodowy kodowymyślacz też niespecjalnie :)
odnoszę wrażenie że autor oryginału miał również z tym problem…
Ja przyznam, że próbowałem to analizować… próbowałem… i nie rozumiem większości kodu
proste: działa to nie ruszać :)
Gdzie zamawiałeś plexi, o ile to nie tajemnica, bo gdzie się nie zwrócę to chcą dużo więcej ?
Mcm tech
bardzo fajny projekt!
Ten sok na zdjęciu to jakaś reklama?
xD
Myślałem że to z płyt CD. “
Ale to nie działa
możesz rozwinąć swoją myśl ? :)
czy na pewno przycisk jest dobrze podłączony ?
wsad generuje mi błędy i nie wiem o co chodzi z tą biblioteką
IC:\Users\Janek\Documents\Arduino\libraries\Adafruit_NeoPixel-1.1.8″ “-IC:\Users\Janek\Documents\Arduino\libraries\FastLED-3.2.6” “-IC:\Users\Janek\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23\libraries\SoftwareSerial\src” “C:\Users\Janek\AppData\Local\Temp\arduino_build_482076\sketch\polYU.ino.cpp” -o “C:\Users\Janek\AppData\Local\Temp\arduino_build_482076\sketch\polYU.ino.cpp.o”
In file included from C:\Users\Janek\Documents\Arduino\polYU\polYU.ino:2:0:
C:\Users\Janek\Documents\Arduino\libraries\FastLED-3.2.6/FastLED.h:14:21: note: #pragma message: FastLED version 3.002.006
# pragma message “FastLED version 3.002.006”
za dużo się skopiowało
In file included from C:\Users\Janek\Documents\Arduino\polYU\polYU.ino:2:0:
C:\Users\Janek\Documents\Arduino\libraries\FastLED-3.2.6/FastLED.h:14:21: note: #pragma message: FastLED version 3.002.006
# pragma message “FastLED version 3.002.006”
gdzie tu masz błąd?
raport błędów jest długi. Jak załączyć plik tutaj nie wiem.
https://drive.google.com/open?id=1GKZrP3Fd4ccidkbtDISIag36A_4MsZK5
spróbuj z tego pliku, u mnie działa wszystko OK, może brakuje ci jakiejś biblioteki ?
Uporałem się z tym. Pousuwałem kilka rzeczy z opisów i zaktualizowałem biblioteki. Pytałem o FastLED bo nie rozumiałem tej linijki w raporcie błędów. Mam pytanie jeszcze o ten przycisk czy na pewno on powinien być między DO/RX a GND ?
Przycisk masz zdefiniowany w programie. Dokładnie tak ma być podpięty.
Dziękuję bardzo Wszystko funkcjonuje poprawnie Czas na część mechaniczną.
hetm4n byłbyś w stanie podesłać zwymiarowaną podstawę, półwałek, dekielek oraz dystanse? Czy mógłbyś też podesłać link do paska LED skąd zamawiałeś? Będę Ci niezmiernie wdzięczny jeśli udzielisz mi odpowiedzi na moje pytania. Dziękuję
Mati przeczytaj tekst tam wszystko jest
Jeszcze raz dziękuje za fantastyczny projekt Wykonałem go dla mojego wnuka. Filip bo tak się nazywa mówi do swojego młodszego brata “Dlaczego tak krzyczysz wieża się na ciebie gniewa i jest cała czerwona”. Domontowałem moduł mikrofonu na przełączniku.
Pozdrawiam wszystkich serdecznie.
Witam,
Mi to jakoś słabo działa, z kondesatorem 1uF nic się nie dzieje, bez coś się tam zmienia ale z pewnością nie tak jak na video. Czy to działa przy 16 diodach (N_PIXELS poprawiłem na 16) ?
powinno działać nawet na 16, zresztą do próby możesz wklepać 26 i powinno migać , jak to masz dokładnie podłączone?
dokładnie tak jak jest na schemacie, podłączam do wyjścia na słuchawki od laptopa. Migać migają ale nie ma sensownego efektu jak na wideo
wszystko działa już jak na wideo :) rezystory źle stykały na płytce stykowej , działa super
wielki dzieki
Super projekt. Proszę o info jaki kondensator? Rezystory 1k?