Guest User

Untitled

a guest
Oct 3rd, 2020
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.45 KB | None | 0 0
  1. #define FASTLED_INTERRUPT_RETRY_COUNT 1
  2. #define FASTLED_ALLOW_INTERRUPTS 1
  3. #define USE_OCTOWS2811
  4.  
  5. #include <OctoWS2811.h>
  6. #include <MIDI.h>
  7. #include <FastLED.h>
  8. #include <SD.h>
  9.  
  10.  
  11. // DEFIIIIINEEEE
  12.  
  13. #define NUM_LEDS_PER_STRIP 256
  14. #define NUM_STRIPS 8
  15. #define NUM_PIXELS 2048
  16. #define BRIGHTNESS 32
  17. #define UPDATE_TIME 22 //ms between each LED update
  18.  
  19.  
  20. //VARIABLES
  21.  
  22. CRGB leds[NUM_PIXELS];
  23. CRGBPalette16 VUPalette;
  24. CRGB palettes[18][4];
  25. CRGB modcolor;
  26. CRGB modcolor2;
  27. CRGB modcolor3;
  28.  
  29. unsigned int previousMillis; //holds the previous millis
  30. unsigned int fpsMillis;
  31. unsigned int prevMil;
  32. unsigned int saveMillis;
  33.  
  34. int fpsCount = 0;
  35. int fpsLoop = 0;
  36. int saveCount = 0;
  37.  
  38. int ringMatrix[3][17];
  39.  
  40. int shift1 = 0;
  41. int cc[127];
  42. int nrpn[512];
  43. int runner = 0;
  44. int cyclecolor[4];
  45. int times = 10;
  46. int cyclecounter = 0;
  47. int moddot[32];
  48. int moddotnrpn[32];
  49. int shiftdot[32];
  50. int pi;
  51. int pj;
  52.  
  53. int bpmGlobal = 100;
  54. int bpmGlobal256 = 0;
  55. int bpmGlobal27 = 0;
  56. int bpmGlobalTrigger = 0;
  57. int periodGlobal = 60000 / bpmGlobal;
  58.  
  59. bool pickedMode = 0;
  60. int saverMode;
  61. int saveTime = 8000; //800-23sec @30 . // . 1000 = 14sec @UPDATE_TIME 14 hmmmmm.... 14 = 14
  62. int saveChangeTime = 15000;
  63.  
  64. File presetFile;
  65. const int chipSelect = BUILTIN_SDCARD;
  66.  
  67.  
  68.  
  69.  
  70. //MIDI_CREATE_DEFAULT_INSTANCE();
  71. MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI); // teensy pin 8 & 9
  72.  
  73. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  74. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76.  
  77.  
  78. void setup() {
  79. randomSeed(analogRead(0));
  80. delay(300);
  81. LEDS.addLeds<OCTOWS2811>(leds, NUM_LEDS_PER_STRIP);
  82. LEDS.setBrightness(BRIGHTNESS);
  83. clearLEDRingAll();
  84. setPalettes();
  85. setVUPalette();
  86. setcyclecolor();
  87. setRingMatrix();
  88. MIDI.begin();
  89. Serial.begin(9600);
  90. Serial.println("RGB LED RING CONTROL v5");
  91. saveMillis = millis();
  92.  
  93.  
  94. Serial.print("Initializing SD card...");
  95.  
  96. if (!SD.begin(chipSelect)) {
  97. Serial.println("initialization failed!");
  98. return;
  99. }
  100. Serial.println("initialization done.");
  101. }
  102.  
  103.  
  104.  
  105. void loop() {
  106.  
  107. /////// READ NEW MIDI DATA, UPDATE CC ARRAY
  108. midiParse();
  109.  
  110. /////// run this loop every "times" milliseconds
  111. if (millis() >= previousMillis + UPDATE_TIME) {
  112.  
  113. previousMillis = millis();
  114. fpsCount++;
  115. saveCount++;
  116. if (runner < NUM_PIXELS - 1) runner++; else runner = 0;
  117.  
  118. fpsCounter();
  119.  
  120. updateLEDRings();
  121.  
  122.  
  123. /////// OH WAIT MAYBE START SCREENSAVER?
  124. if (saveCount > saveTime) screensaver();
  125.  
  126. /////// UPDATE LEDs AND GO SMOKE A SPLIFF
  127. LEDS.show();
  128.  
  129. /////// GET READY FOR NEXT ROUND
  130. clearLEDRingAll(); // delete old LED values
  131.  
  132. }
  133. fpsLoop++;
  134. }
  135.  
  136.  
  137. void updateLEDRings() {
  138. delay(1);
  139. /////// SET LEDS ARRAY TO NEW VALUES FROM CC ARRAY
  140. //Serial.println(nrpn[150]);
  141.  
  142. // PRESET
  143.  
  144. setLEDRingLine(1, 26, CHSV((runner % 1024) / 4 , 255, 255));
  145.  
  146.  
  147. setLEDRingDot(6, map(nrpn[51], 0, 4095, 0, 26), COLLFO1);
  148.  
  149.  
  150. for (int j = 0; j < 9; j++) {
  151. for (int i = 0; i < 31; i++) {
  152. int l = nrpn[201 + (10 * moddotnrpn[i]) + j];
  153. if (l > 0)
  154. leds[(moddot[i] * 32) - 1].addToRGB((l >> 6) + 20);
  155. }
  156. }
  157.  
  158.  
  159.  
  160. }
  161.  
  162.  
  163. void setPalettes() {
  164. for (int i = 0; i < 4; i++) {
  165. palettes[0][i] = RED;
  166. palettes[1][i] = BLUE;
  167. palettes[2][i] = GREEN;
  168.  
  169. palettes[3][i] = YELLOW;
  170. palettes[4][i] = ORANGE;
  171. palettes[5][i] = PINK;
  172. palettes[6][i] = WHITE;
  173. palettes[7][i] = CRGB::Aqua;
  174. palettes[8][i] = CRGB::Aquamarine;
  175. palettes[9][i] = CRGB::CadetBlue;
  176. palettes[10][i] = CRGB::CRGB::Coral;
  177. palettes[11][i] = CRGB::Aquamarine;
  178. palettes[12][i] = CRGB::Aquamarine;
  179.  
  180. }
  181.  
  182.  
  183. for (int i = 0; i < 16; i++) {
  184. palettes[i][0].addToRGB(30);
  185. palettes[i][2].fadeLightBy(80);
  186. palettes[i][3].fadeLightBy(160);
  187. }
  188. }
  189.  
  190. void setVUPalette() {
  191. VUPalette[0] = CRGB(0, 100, 0);
  192. VUPalette[1] = CRGB(0, 170, 0);
  193. VUPalette[2] = CRGB(0, 255, 0);
  194. VUPalette[3] = CRGB(200, 255, 0);
  195. VUPalette[4] = CRGB::Yellow;
  196. VUPalette[5] = CRGB(255, 150, 0);
  197. VUPalette[6] = CRGB(255, 0, 0);
  198. VUPalette[7] = CRGB(255, 0, 0);
  199. }
  200.  
  201. void setcyclecolor() {
  202. cyclecolor[0] = 0xFF0000;
  203. cyclecolor[1] = 0xFF8f00;
  204. cyclecolor[2] = 0x0000FF;
  205. cyclecolor[3] = 0x00ff00;
  206.  
  207. }
  208. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  209. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  210. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  211. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  212. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  213. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  214. //////////// LED RING FUNCTIONS
  215. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  216. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  217. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  218. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  219. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  220. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  221.  
  222. void clearLEDRing(int ringNr) {
  223. int offseti = (ringNr - 1) * 32;
  224. for (int i = 0; i < 32; i++) leds[offseti + i] = 0;
  225. }
  226.  
  227. void clearLEDRingAll(void) {
  228. for (int i = 0; i < NUM_PIXELS; i++) leds[i] = 0;
  229. }
  230.  
  231.  
  232. // Sets one LED at VALUE to COLOR
  233. void setLEDRingDot(int ringNr, int value, CRGB color) {
  234. leds[(ringNr - 1) * 32 + 2 + value] = color;
  235. }
  236.  
  237. // Sets all LEDs up to VALUE to COLOR
  238. void setLEDRingLine(int ringNr, int value, CRGB color) {
  239. int offseti = (ringNr - 1) * 32 + 2;
  240. for (int i = 0; i <= value; i++) {
  241. leds[offseti + i] = color;
  242. }
  243. }
  244.  
  245.  
  246. // VU Style green-yellow-red
  247. void setLEDRingVU(int ringNr, int value) {
  248. int offseti = (ringNr - 1) * 32 + 2;
  249. for (int i = 0; i <= value; i++) {
  250. leds[offseti + i] = ColorFromPalette(VUPalette, i * 4, 255, LINEARBLEND);
  251. }
  252. }
  253.  
  254.  
  255. // VU Style green-yellow-red line
  256. void setLEDRingVULine(int ringNr, int value) {
  257. int offseti = (ringNr - 1) * 32 + 2;
  258. for (int i = 0; i <= value; i++) {
  259. leds[offseti + i] = ColorFromPalette(VUPalette, value * 4, 255, LINEARBLEND);
  260. }
  261. }
  262.  
  263. // Divides LED Ring into SEGMENTS
  264. void setLEDRingDivide(int ringNr, int segments, CRGB color, CRGB bgcolor) {
  265. int stepSize = 31 / segments;
  266. int offseti = (ringNr - 1) * 32 + 2;
  267. for (int i = 0; i < 32; i++) leds[offseti + i] = bgcolor;
  268. for (int i = 0; i < segments + 1; i++) leds[offseti + (i * stepSize)] = color;
  269. }
  270.  
  271.  
  272. // Multiply LED Ring by STEPSIZE
  273. void setLEDRingMultiply(int ringNr, int stepSize, CRGB color, CRGB bgcolor) {
  274. if (stepSize == 0) stepSize = 32;
  275. int offseti = (ringNr - 1) * 32 + 2;
  276. for (int i = 0; i < 32; i++) leds[offseti + i] = bgcolor;
  277. for (int i = 0; i < 32; i = i + stepSize) leds[offseti + i] = color;
  278. }
  279.  
  280.  
  281. // Multiply LED Ring by STEPSIZE, Fading out
  282. void setLEDRingMultiplyFade(int ringNr, int stepSize, CRGB color, CRGB bgcolor) {
  283. if (stepSize == 0) stepSize = 32;
  284. int offseti = (ringNr - 1) * 32 + 2;
  285. for (int i = 0; i < 32; i++) leds[offseti + i] = bgcolor;
  286. for (int i = stepSize; i < 32; i = i + stepSize) {
  287. leds[offseti + i] = color;
  288. leds[offseti + i] = (i * 8);
  289. }
  290. leds[offseti] = color;
  291. }
  292.  
  293.  
  294. void setLEDRingFadeIn(int ringNr, int value, CRGB color) {
  295. int offseti = (ringNr - 1) * 32 + 2;
  296. int j = 255 / value;
  297. for (int i = 0; i <= value; i++) {
  298. leds[offseti + i] = CRGB(
  299. map(color.r, 0 , 255, 0, i * j),
  300. map(color.g, 0 , 255, 0, i * j),
  301. map(color.b, 0 , 255, 0, i * j)
  302.  
  303. );
  304. }
  305. leds[offseti + value] = color;
  306. }
  307.  
  308. void setLEDRingFadeOut(int ringNr, int value, CRGB color) {
  309. int offseti = (ringNr - 1) * 32 + 2;
  310. int j = 255 / value;
  311. for (int i = 0; i <= value; i++) {
  312. leds[offseti + i] = CRGB(
  313. map(color.r, 0 , 255, 0, 255 - (i * j)),
  314. map(color.g, 0 , 255, 0, 255 - (i * j)),
  315. map(color.b, 0 , 255, 0, 255 - (i * j))
  316. );
  317. }
  318. }
  319.  
  320. // block segment number VALUE out of SEGMENTS
  321. void setLEDRingSegments(int ringNr, int value, int segments, CRGB color) {
  322. int stepSize = 216 / segments;
  323. int offseti = (ringNr - 1) * 32 + 2 + ((value * stepSize) >> 3);
  324. for (int i = 0; i <= (stepSize >> 3); i++) {
  325. leds[offseti + i] = color;
  326. }
  327. }
  328.  
  329. ////////////////////////////////////////////////////////////////////////////////////
  330. /////////////////////////PANNING / BIPOLAR///////////////////////////////////////////////////////////
  331. ////////////////////////////////////////////////////////////////////////////////////
  332.  
  333.  
  334. // Panning v2
  335. void setLEDRingPan(int ringNr, int value, CRGB valcolor, CRGB centercolor, CRGB linecolor) {
  336. int offseti = (ringNr - 1) * 32 + 15;
  337. if (value > 0) {
  338. for (int i = 1; i < value; i++) leds[offseti + i] = linecolor;
  339. }
  340. else if (value < 0) {
  341. for (int i = -1; i > value ; i--) leds[offseti + i] = linecolor;
  342. }
  343. leds[offseti + value] = valcolor;
  344. leds[offseti] = centercolor;
  345. }
  346.  
  347. void setLEDRingPitch(int ringNr, int value, CRGB valcolor, CRGB centercolor) {
  348. int offseti = (ringNr - 1) * 32 + 15;
  349. leds[offseti] = centercolor;
  350. if (abs(value) > 24) {
  351. if (value > 0) leds[offseti + value - 24] = valcolor.subtractFromRGB(180);
  352. else leds[offseti + value + 24] = valcolor.subtractFromRGB(180);
  353. }
  354. else if (abs(value) > 12) {
  355. if (value > 0) leds[offseti + value - 12] = valcolor.subtractFromRGB(100);
  356. else leds[offseti + value + 12] = valcolor.subtractFromRGB(100);
  357. }
  358. else leds[offseti + value] = valcolor;
  359. }
  360.  
  361. // QPanning
  362. void setLEDRingQ(int ringNr, int value, CRGB valcolor, CRGB centercolor, CRGB linecolor) {
  363. int offseti = (ringNr - 1) * 32 + 15;
  364. for (int i = 1; i <= value; i++) {
  365. leds[offseti + i] = linecolor;
  366. leds[offseti - i] = linecolor;
  367. }
  368. leds[offseti + value] = valcolor;
  369. leds[offseti - value] = valcolor;
  370. leds[offseti] = centercolor;
  371. }
  372.  
  373. ////////////////////////////////////////////////////////////////////////////////////
  374. /////////////////////////SINGLE LED///////////////////////////////////////////////////////////
  375. ////////////////////////////////////////////////////////////////////////////////////
  376.  
  377.  
  378. // Blink one LED at LEDNR to COLOR at BPM speed
  379. void setLEDBlink(int ledNr, int bpm, CRGB color) {
  380.  
  381. int period = 60000 / bpm;
  382. static unsigned int prevMil;
  383.  
  384. if (millis() >= (prevMil + period)) {
  385. prevMil = millis();
  386. }
  387.  
  388. else if (millis() >= (prevMil + 90)) {
  389. leds[ledNr] = BLACK;
  390. }
  391.  
  392. else {
  393. leds[ledNr] = color;
  394. }
  395. }
  396.  
  397.  
  398. // Pulse one LED at LEDNR to COLOR at BPM speed
  399. void setLEDPulse(int ledNr, int bpm, CRGB color) {
  400. int period = 60000 / bpm;
  401. static CRGB col2;
  402. static unsigned int prevMil2;
  403.  
  404. if (millis() >= (prevMil2 + period)) {
  405. prevMil2 = millis();
  406. col2 = color;
  407.  
  408. }
  409.  
  410. col2.subtractFromRGB(4);
  411. leds[ledNr] = col2;
  412.  
  413. }
  414.  
  415.  
  416. void setLEDVLine (int value, CRGB color) {
  417. //16x17horiz pixel = 272
  418. int ringHoriz = value >> 4;
  419. for (int i = 0; i <= 2; i++) {
  420. setLEDRingHLine(ringMatrix[i][ringHoriz], value % 16, color);
  421. }
  422. }
  423.  
  424. void setLEDHLine (int value, CRGB color) {
  425. //16x17horiz pixel = 272
  426. int ringVert = value >> 4;
  427. for (int i = 0; i < 17; i++) {
  428. setLEDRingVLine(ringMatrix[ringVert][i], value % 16, color);
  429. }
  430. }
  431.  
  432.  
  433. void setLEDHRGBLine (int value, CRGB color) {
  434. //16x17horiz pixel = 272
  435. int ringVert = value >> 4;
  436. for (int i = 0; i < 17; i++) {
  437. setLEDRingVLine(ringMatrix[ringVert][i], value % 16, CHSV(i << 4, 255, 255));
  438. }
  439. }
  440.  
  441. void setLEDRingNightrider(int ringNr, CRGB color) {
  442. int offseti = (ringNr - 1) * 32 + 2;
  443. static bool dir;
  444. if (bpmGlobalTrigger) {
  445. leds[offseti + bpmGlobal27] = color;
  446. leds[offseti + bpmGlobal27 - 1] = color.nscale8( 192);
  447. leds[offseti + bpmGlobal27 - 2] = color.nscale8( 128);
  448. leds[offseti + bpmGlobal27 - 3] = color.nscale8( 96);
  449. leds[offseti + bpmGlobal27 - 4] = color.nscale8( 64);
  450. leds[offseti + bpmGlobal27 - 5] = color.nscale8( 32);
  451. leds[offseti + bpmGlobal27 - 6] = color.nscale8( 16);
  452. }
  453. else {
  454. leds[offseti - bpmGlobal27 + 27] = color;
  455. leds[offseti - bpmGlobal27 + 28] = color.nscale8( 192);
  456. leds[offseti - bpmGlobal27 + 29] = color.nscale8( 128);
  457. leds[offseti - bpmGlobal27 + 30] = color.nscale8( 96);
  458. leds[offseti - bpmGlobal27 + 31] = color.nscale8( 64);
  459. leds[offseti - bpmGlobal27 + 32] = color.nscale8( 32);
  460. leds[offseti - bpmGlobal27 + 33] = color.nscale8( 16);
  461. }
  462. if (bpmGlobal27 == 0) dir = !dir;
  463. /*
  464. Serial.print(dir);
  465. Serial.print(" . ");
  466. Serial.print(bpmGlobal27);
  467. Serial.print(" . ");
  468. Serial.print(bpmGlobalTrigger);
  469. Serial.println(" . ");
  470. */
  471. }
  472.  
  473.  
  474.  
  475. ////////////////////////////////////////////////////////////////////////////////////
  476. /////////////////////////HELPER / OTHERS///////////////////////////////////////////////////////////
  477. ////////////////////////////////////////////////////////////////////////////////////
  478.  
  479.  
  480. // swipe dot
  481. void setLEDRingSwipe(int ringNr, CRGB color) {
  482. int offseti = (ringNr - 1) * 32 + 2;
  483. leds[offseti + (runner % 30)] = color;
  484. }
  485.  
  486. void setLEDRingSwipeSlow(int ringNr, CRGB color) {
  487. int offseti = (ringNr - 1) * 32 + 2;
  488. leds[offseti + ((runner >> 1) % 30)] = color;
  489. }
  490. void setLEDRingSwipeSlow2(int ringNr, CRGB color) {
  491. int offseti = (ringNr - 1) * 32 + 2;
  492. leds[offseti + ((runner >> 2) % 30)] = color;
  493. }
  494. void setLEDRingSwipeSlow4(int ringNr, CRGB color) {
  495. int offseti = (ringNr - 1) * 32 + 2;
  496. leds[offseti + ((runner >> 3) % 30)] = color;
  497. }
  498.  
  499. void setLEDRingBlinkFull(int ringNr, CRGB color) {
  500. int offseti = (ringNr - 1) * 32 + 2;
  501. if ((runner % 16) < 8) {
  502. for (int i = 0; i < 27; i++) {
  503. leds[offseti + i] = color;
  504. }
  505. } else {
  506. for (int i = 0; i < 27; i++) {
  507. leds[offseti + i] = 0x000000;
  508. }
  509. }
  510. }
  511.  
  512.  
  513. void setLEDModDot(CRGB color) {
  514. for (int i = 0; i < 31; i++) {
  515. leds[(moddot[i] * 32) - 1] = color;
  516. }
  517. }
  518.  
  519.  
  520.  
  521. void setLEDRingVLine(int ringNr, int value, CRGB color) {
  522. int offseti = (ringNr * 32) - 17;
  523. leds[offseti + value] += color;
  524. leds[offseti - value] += color;
  525. }
  526.  
  527. void setLEDRingHRand(int ringNr, int value, CRGB color) {
  528. int offseti = (ringNr * 32) - 17;
  529. bool odd = random(2);
  530. //Serial.println(odd);
  531.  
  532. if (odd) leds[offseti + value] = color;
  533. else leds[offseti - value] = color;
  534. }
  535.  
  536. void setLEDRingHLine(int ringNr, int value, CRGB color) {
  537. int offseti = (ringNr * 32) - 25;
  538. if (value < 8) {
  539. leds[offseti + value] += color;
  540. leds[offseti - value] += color;
  541. }
  542. else {
  543. leds[offseti + value] += color;
  544. leds[offseti + 32 - value] += color;
  545. }
  546.  
  547. }
  548.  
  549.  
  550.  
  551. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  552. ////////////////////////////////SCREENSAVER////////////////////////////////////////////////////////////////////////////
  553. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  554. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  555. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  556. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  557. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  558. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  559. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  560. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  561. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  562. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  563. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  564.  
  565. void saverSnowfall(int spd) {
  566. while (!MIDI.read()) {
  567. int l = random(255);
  568. if ((saveCount % (spd > 1)) == 0) {
  569. if ((saveCount >> (spd - 3)) <= 17) setLEDRingHRand(ringMatrix[0][random(17)], random((saveCount >> (spd - 3)) % 17), CRGB(l, l, l));
  570. else if ((saveCount >> (spd - 3)) <= 34) {
  571. setLEDRingHRand(ringMatrix[0][random(17)], random(17), CRGB(l, l, l));
  572. setLEDRingHRand(ringMatrix[1][random(17)], random((saveCount >> (spd - 3)) % 17), CRGB(l, l, l));
  573. }
  574. else if ((saveCount >> (spd - 3)) > 34) {
  575. setLEDRingHRand(ringMatrix[0][random(17)], random(17), CRGB(l, l, l));
  576. setLEDRingHRand(ringMatrix[1][random(17)], random(17), CRGB(l, l, l));
  577. setLEDRingHRand(ringMatrix[2][random(17)], random((saveCount >> (spd - 3)) % 17), CRGB(l, l, l));
  578. }
  579. }
  580. for (int i = 0; i < 2047; i++) leds[i].fadeToBlackBy(1);
  581. delay(spd << 1);
  582. LEDS.show();
  583. saveCount++;
  584. if (millis() > (saveMillis + saveChangeTime)) {
  585. pickedMode = 0;
  586. break;
  587. }
  588. }
  589. if (pickedMode) {
  590. //saveCount = saveTime + 2; //test & copy to all
  591. pickedMode = 0;
  592. }
  593. }
  594.  
  595. void saverAddRandomBWFade(int spd) {
  596. while (!MIDI.read()) {
  597. int l = random (255);
  598. leds[random(2048)] += CRGB (l, l, l);
  599. for (int i = 0; i < 2047; i++) leds[i].fadeToBlackBy(1);
  600. delay(spd);
  601. LEDS.show();
  602. if (millis() > (saveMillis + saveChangeTime)) {
  603. pickedMode = 0;
  604. break;
  605. }
  606. }
  607. pickedMode = 0;
  608. }
  609.  
  610. void saverAddRandom(int spd) {
  611. while (!MIDI.read()) {
  612. leds[random(2048)] += CHSV(random(255), random(255), random(64));
  613. delay(spd);
  614. LEDS.show();
  615. if (millis() > (saveMillis + saveChangeTime)) {
  616. pickedMode = 0;
  617. break;
  618. }
  619. }
  620. pickedMode = 0;
  621. }
  622.  
  623.  
  624. /////////////// non interrupt
  625. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  626.  
  627. void saverHWave(int spd, int lngth, CRGB color) {
  628. int dir = (((saveCount << spd) >> 2) % ((17 + lngth) * 8)) >> 3;
  629. //Serial.println(dir);
  630. for (int j = 0; j < 3; j++) {
  631. for (int k = 0; k < lngth; k++) {
  632. CRGB c2 = color;
  633. if (((dir - k) > 0) && ((dir - k) < 17)) setLEDRingLine(ringMatrix[j][dir - k], 32, c2.subtractFromRGB((k * lngth * 4)));
  634. }
  635. }
  636. }
  637.  
  638.  
  639.  
  640. void saverHueSnake (int spd) {
  641. int dir = ((saveCount << spd) % 2300);
  642. for (int i = 0; i < 255; i++) {
  643. int k = 2048 - dir + i;
  644. if ((k > 0) && (k < 2048)) leds[k] += CHSV(dir % 255, 255, i);
  645. }
  646. }
  647.  
  648. void saverNightriderFine (int spd, int nwidth, CRGB color) {
  649.  
  650. int dir = (((saveCount << spd) >> 2) % 544);
  651. if (dir > 272)dir = 544 - dir;
  652. for (int i = 0; i < nwidth; i++) {
  653. if ((dir + i) < 272) setLEDVLine(dir + i, color); // needs >=0 check
  654. setLEDVLine(dir - i, color);
  655. }
  656.  
  657. }
  658.  
  659. void saverNightriderFineH (int spd, int nwidth, CRGB color) {
  660.  
  661. int dir = (((saveCount << spd) >> 2) % 93);
  662. if (dir > 47) dir = 93 - dir;
  663. for (int i = 0; i < nwidth; i++) {
  664. if ((dir + i) < 47) setLEDHLine(dir + i, color); // needs >=0 check
  665. setLEDHLine(dir, color);
  666. }
  667. }
  668.  
  669. void saverNightriderFineHRGB (int spd, int nwidth, CRGB color) {
  670.  
  671. int dir = (((saveCount << spd) >> 2) % 93);
  672. if (dir > 47) dir = 93 - dir;
  673. for (int i = 0; i < nwidth; i++) {
  674. if ((dir + i) < 47) setLEDHLine(dir + i, color); // needs >=0 check
  675. setLEDHRGBLine(dir, color);
  676. }
  677. }
  678.  
  679.  
  680.  
  681.  
  682. void saverHSwipeAll(int spd) {
  683.  
  684. int dir = ((saveCount << spd) % 128) >> 3;
  685. for (int i = 0; i < 17; i++) {
  686. for (int j = 0; j <= 2; j++) setLEDRingHLine(ringMatrix[j][i], dir, RED);
  687. }
  688. }
  689.  
  690. void saverVSwipeAll (int spd) {
  691. int dir = ((saveCount << spd) % 384) >> 3;
  692.  
  693. if (dir < 16) {
  694. for (int i = 0; i < 17; i++) {
  695. setLEDRingVLine(ringMatrix[0][i], dir, RED);
  696. }
  697. }
  698. else if (dir < 32) {
  699. for (int i = 0; i < 17; i++) {
  700. setLEDRingVLine(ringMatrix[1][i], dir - 16, RED);
  701. }
  702. }
  703. else if (dir < 48) {
  704. for (int i = 0; i < 17; i++) {
  705. setLEDRingVLine(ringMatrix[2][i], dir - 32, RED);
  706. }
  707. }
  708. }
  709.  
  710. void saverNightriderCoarse (int spd, CRGB color) {
  711.  
  712.  
  713. int dir = ((saveCount << spd) % 256) >> 3;
  714. if (dir >= 17) dir = 32 - dir;
  715. for (int i = 0; i <= 2; i++) {
  716. setLEDRingLine(ringMatrix[i][dir], 27, color);
  717.  
  718. }
  719.  
  720. delay(spd + 1);
  721. }
  722. /*
  723. void saverNightriderCoarse (int spd, CRGB color) {
  724.  
  725.  
  726. int dir = ((saveCount << spd) % 256) >> 3;
  727. if (dir >= 17) dir = 32 - dir;
  728. if (dir < 17) && ((dir + k) >= 0)) setLEDRingLine(ringMatrix[i][dir + k], 27, col );
  729. if (dir < 17) {
  730. for (int i = 0; i <= 2; i++) {
  731. setLEDRingLine(ringMatrix[i][dir], 27, color);
  732.  
  733. }
  734. }
  735. else {
  736. for (int i = 0; i <= 2; i++) {
  737. setLEDRingLine(ringMatrix[i][33 - dir], 27, RED);
  738. }
  739. }
  740. delay(spd + 1);
  741. }
  742. */
  743.  
  744. void saverNightriderCoarseFade(int spd, CRGB color) {
  745.  
  746.  
  747. int dir = ((saveCount << spd) % 272) >> 3;
  748. if (dir >= 18) dir = 34 - dir;
  749. for (int i = 0; i <= 2; i++) {
  750. for (int k = -2; k <= 2; k++) {
  751. CRGB col = color;
  752. if (abs(k) > 0) col = col / (abs(k) << 2);
  753. if (((dir + k) < 17) && ((dir + k) >= 0)) setLEDRingLine(ringMatrix[i][dir + k], 27, col );
  754. Serial.println(abs(k));
  755. }
  756. }
  757.  
  758. delay(spd + 1);
  759. }
Advertisement
Add Comment
Please, Sign In to add comment