|
| 1 | +boolean MSGEQ7read() { |
| 2 | + return fft_available; |
| 3 | +} |
| 4 | + |
| 5 | + |
| 6 | +#define MSGEQ7_OUT_MAX 255 |
| 7 | + |
| 8 | +int MSGEQ7get(int band, int channel) { |
| 9 | + int value = map((fftData[band] * 100), 0, 100, 0, MSGEQ7_OUT_MAX); |
| 10 | +// Serial.printf("Band: %u = %u\n", band, value); |
| 11 | + return value; |
| 12 | +} |
| 13 | + |
| 14 | +int barWidth = (kMatrixWidth / 8) / 2; |
| 15 | +int blockWidth = barWidth * 8; |
| 16 | + |
| 17 | +void drawPixel(int x, int y, CRGB color) { |
| 18 | + leds[XY(x, y)] = color; |
| 19 | +} |
| 20 | + |
| 21 | + |
| 22 | +// Funky plank ----------------------------------------------------------------------------------- |
| 23 | + |
| 24 | +void FunkyPlank() { |
| 25 | + |
| 26 | + bool newReading = MSGEQ7read(); |
| 27 | + |
| 28 | + // Led strip output |
| 29 | + if (newReading) { |
| 30 | + |
| 31 | + // display values of left channel on DMD |
| 32 | + for (int band = 0; band < 8; band++ ) |
| 33 | + { |
| 34 | + int hue = MSGEQ7get(band, 0); |
| 35 | + int v = map(MSGEQ7get(band, 0), 0, MSGEQ7_OUT_MAX, 10, 255); |
| 36 | + for (int b = 0; b < barWidth; b++) { |
| 37 | + int xpos = blockWidth - (barWidth * band) - b; |
| 38 | + drawPixel(xpos, 0, CHSV(hue, 255, v)); |
| 39 | +// Serial.printf("band: %u, hue: %u v: %u\n", band, hue, v); |
| 40 | + // drawPixel((offset + band + 1), 0, CHSV(hue, 255, 255)); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + // display values of left channel on DMD |
| 45 | + for (int band = 0; band < 8; band++ ) |
| 46 | + { |
| 47 | + int hue = MSGEQ7get(band, 1); |
| 48 | + int v = map(MSGEQ7get(band, 1), 0, MSGEQ7_OUT_MAX, 10, 255); |
| 49 | + for (int b = 0; b < barWidth; b++) { |
| 50 | + int xpos = blockWidth + 1 + (barWidth * band) + b; |
| 51 | + drawPixel(xpos, 0, CHSV(hue, 255, v)); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + FastLED.show(); |
| 56 | + moveUp(); |
| 57 | + |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +void moveUp() { |
| 62 | + // Update the display: |
| 63 | + for (int i = (kMatrixHeight - 1); i >= 0; i--) { |
| 64 | + for (int j = (kMatrixWidth - 1); j >= 0; j--) { |
| 65 | + int src = XY(j, (i - 1)); |
| 66 | + int dst = XY(j, i); |
| 67 | + leds[dst] = leds[src]; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | +// DJ Light ----------------------------------------------------------------------------------- |
| 74 | + |
| 75 | + |
| 76 | +void DJLight() { |
| 77 | + |
| 78 | + bool newReading = MSGEQ7read(); |
| 79 | + |
| 80 | +// int offset = 8; |
| 81 | + |
| 82 | + int mid = NUM_AUDIO_LEDS / 2; |
| 83 | + |
| 84 | + // Led strip output |
| 85 | + if (newReading) { |
| 86 | + |
| 87 | + int bands[8]; |
| 88 | + for (int band = 0; band < 8; band++ ) |
| 89 | + { |
| 90 | + bands[band] = MSGEQ7get(band, 1); |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | +// leds[mid] = CRGB(bands[6], bands[5] / 8, bands[1] / 2); |
| 95 | +// leds[mid].fadeToBlackBy(bands[3] / 12); |
| 96 | + |
| 97 | + |
| 98 | + ledsAudio[mid] = CRGB(bands[5]/2, bands[2]/2, bands[0]/2); |
| 99 | + ledsAudio[mid].fadeToBlackBy((map(bands[1], 0, MSGEQ7_OUT_MAX, 255, 10))); |
| 100 | + |
| 101 | + Serial.printf("RGB: %u %u %u\n", bands[5]/2, bands[2]/2, bands[0]/2); |
| 102 | + |
| 103 | + |
| 104 | + //move to the left |
| 105 | + for (int i = NUM_AUDIO_LEDS - 1; i > mid; i--) { |
| 106 | + ledsAudio[i] = ledsAudio[i - 1]; |
| 107 | + } |
| 108 | + // move to the right |
| 109 | + for (int i = 0; i < mid; i++) { |
| 110 | + ledsAudio[i] = ledsAudio[i + 1]; |
| 111 | + } |
| 112 | + |
| 113 | + EVERY_N_MILLISECONDS(300) { |
| 114 | + // TODO: map to fade |
| 115 | + for (int i = 0; i < NUM_AUDIO_LEDS; i++) { |
| 116 | + ledsAudio[i].fadeToBlackBy(10); |
| 117 | + } |
| 118 | + } |
| 119 | + showSegments(); |
| 120 | + } |
| 121 | +} |
0 commit comments