Run repetitively
| 95 | |
| 96 | // Run repetitively |
| 97 | void loop() { |
| 98 | unsigned int x, y, freqBin; |
| 99 | float level; |
| 100 | |
| 101 | if (fft.available()) { |
| 102 | // freqBin counts which FFT frequency data has been used, |
| 103 | // starting at low frequency |
| 104 | freqBin = 0; |
| 105 | |
| 106 | for (x=0; x < matrix_width; x++) { |
| 107 | // get the volume for each horizontal pixel position |
| 108 | level = fft.read(freqBin, freqBin + frequencyBinsHorizontal[x] - 1); |
| 109 | |
| 110 | // uncomment to see the spectrum in Arduino's Serial Monitor |
| 111 | // Serial.print(level); |
| 112 | // Serial.print(" "); |
| 113 | |
| 114 | for (y=0; y < matrix_height; y++) { |
| 115 | // for each vertical pixel, check if above the threshold |
| 116 | // and turn the LED on or off |
| 117 | if (level >= thresholdVertical[y]) { |
| 118 | leds[xy(x,y)] = CRGB(myColor); |
| 119 | } else { |
| 120 | leds[xy(x,y)] = CRGB::Black; |
| 121 | } |
| 122 | } |
| 123 | // increment the frequency bin count, so we display |
| 124 | // low to higher frequency from left to right |
| 125 | freqBin = freqBin + frequencyBinsHorizontal[x]; |
| 126 | } |
| 127 | // after all pixels set, show them all at the same instant |
| 128 | FastLED.show(); |
| 129 | // Serial.println(); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | // Run once from setup, the compute the vertical levels |