| 
 | 1 | +#include <Adafruit_NeoMatrix.h>  | 
 | 2 | +#include <Adafruit_NeoPixel.h>  | 
 | 3 | +   | 
 | 4 | +#define PIN 6  | 
 | 5 | + | 
 | 6 | +// PANEL SETUP  | 
 | 7 | +int width = 32;  | 
 | 8 | +int height = 8;  | 
 | 9 | +int NUM_LEDS = width * height;  | 
 | 10 | +int band_width = 4;  | 
 | 11 | + | 
 | 12 | +// AUDIO INPUT SETUP  | 
 | 13 | +int strobe = 4;  | 
 | 14 | +int reset = 5;  | 
 | 15 | +int audio1 = A0;  | 
 | 16 | +int audio2 = A1;  | 
 | 17 | +int left[7];  | 
 | 18 | +int right[7];  | 
 | 19 | +int band;  | 
 | 20 | +int audio_input = 0;  | 
 | 21 | +int freq = 0;  | 
 | 22 | +int react_arr[] = {0, 0, 0, 0, 0, 0, 0};  | 
 | 23 | +int prereact_arr[] = {0, 0, 0, 0, 0, 0, 0};  | 
 | 24 | + | 
 | 25 | + | 
 | 26 | +// STANDARD VISUALIZER VARIABLES  | 
 | 27 | +float modifier = 2.5; // CONTROLS SENSITIVITY OF THE LED REACTION  | 
 | 28 | +int loop_max = 0;  | 
 | 29 | +int k = 255; // COLOR WHEEL POSITION  | 
 | 30 | +int decay = 1; // HOW MANY MS BEFORE ONE LIGHT DECAY  | 
 | 31 | +int decay_check = 0;  | 
 | 32 | +//long pre_react = 0; // NEW SPIKE CONVERSION  | 
 | 33 | +//long react = 0; // NUMBER OF LEDs BEING LIT  | 
 | 34 | +long post_react = 0; // OLD SPIKE CONVERSION  | 
 | 35 | + | 
 | 36 | + | 
 | 37 | +// RAINBOW WAVE SETTINGS  | 
 | 38 | +int wheel_speed = 2;  | 
 | 39 | +   | 
 | 40 | +Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(width, height, PIN,  | 
 | 41 | +  NEO_MATRIX_BOTTOM    + NEO_MATRIX_RIGHT +  | 
 | 42 | +  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,  | 
 | 43 | +  NEO_GRB            + NEO_KHZ800);  | 
 | 44 | +   | 
 | 45 | +const uint16_t colors[] = {  | 
 | 46 | +  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};  | 
 | 47 | + | 
 | 48 | + | 
 | 49 | +void readMSGEQ7()  | 
 | 50 | +// Function to read 7 band equalizers  | 
 | 51 | +{  | 
 | 52 | +  digitalWrite(reset, HIGH);  | 
 | 53 | +  digitalWrite(reset, LOW);  | 
 | 54 | +  for(band=0; band <7; band++)  | 
 | 55 | +  {  | 
 | 56 | +    digitalWrite(strobe, LOW); // strobe pin on the shield - kicks the IC up to the next band   | 
 | 57 | +    delayMicroseconds(30); //   | 
 | 58 | +    left[band] = analogRead(audio1) * modifier; // store left band reading  | 
 | 59 | +    right[band] = analogRead(audio2) * modifier; // ... and the right  | 
 | 60 | + | 
 | 61 | +    if (left[band] > 1023)  | 
 | 62 | +      left[band] = 1023;  | 
 | 63 | +    if (right[band] > 1023)  | 
 | 64 | +      right[band] = 1023;  | 
 | 65 | +        | 
 | 66 | +    digitalWrite(strobe, HIGH);   | 
 | 67 | +  }  | 
 | 68 | +}  | 
 | 69 | + | 
 | 70 | + | 
 | 71 | + | 
 | 72 | +uint32_t Scroll(int pos) {  | 
 | 73 | +  int g;  | 
 | 74 | +  int r;  | 
 | 75 | +  int b;  | 
 | 76 | +  if(pos < 85) {  | 
 | 77 | +    g = 0;  | 
 | 78 | +    r = ((float)pos / 85.0f) * 255.0f;  | 
 | 79 | +    b = 255 - r;  | 
 | 80 | +  } else if(pos < 170) {  | 
 | 81 | +    g = ((float)(pos - 85) / 85.0f) * 255.0f;  | 
 | 82 | +    r = 255 - g;  | 
 | 83 | +    b = 0;  | 
 | 84 | +  } else if(pos < 256) {  | 
 | 85 | +    b = ((float)(pos - 170) / 85.0f) * 255.0f;  | 
 | 86 | +    g = 255 - b;  | 
 | 87 | +    r = 1;  | 
 | 88 | +  }  | 
 | 89 | +  return matrix.Color(g, r, b);  | 
 | 90 | +}  | 
 | 91 | + | 
 | 92 | + | 
 | 93 | + | 
 | 94 | + | 
 | 95 | +void singleRainbow()  | 
 | 96 | +{  | 
 | 97 | +  int band_width = width / 7;  | 
 | 98 | +  for(int x = 6, x2 = 0; x >= 0, x2 < 7; x--, x2++)  | 
 | 99 | +  {  | 
 | 100 | +    for(int i = height - 1; i >= 0; i--) {  | 
 | 101 | +      for(int w = 1; w <= band_width; w++)  | 
 | 102 | +      {  | 
 | 103 | +        if (i < react_arr[x])  | 
 | 104 | +          matrix.drawPixel((x2 * band_width) + w, i, Scroll((i * 256 / 50 + k) % 256));  | 
 | 105 | +          //matrix.setPixelColor((8 * x) + i, Scroll((i * 256 / 50 + k) % 256));  | 
 | 106 | +            | 
 | 107 | +        else  | 
 | 108 | +          matrix.drawPixel((x2 * band_width) + w, i, (0, 0, 0));  | 
 | 109 | +          //matrix.setPixelColor((8 * x) + i, (0, 0, 0));     | 
 | 110 | +      }     | 
 | 111 | +    }  | 
 | 112 | +  }  | 
 | 113 | +  matrix.show();   | 
 | 114 | +}  | 
 | 115 | + | 
 | 116 | + | 
 | 117 | +void convertSingle(int i)  | 
 | 118 | +{  | 
 | 119 | +  if (left[i] > right[i])  | 
 | 120 | +    audio_input = left[i];  | 
 | 121 | +  else  | 
 | 122 | +    audio_input = right[i];  | 
 | 123 | + | 
 | 124 | +  if (audio_input > 80 * modifier)  | 
 | 125 | +  {  | 
 | 126 | +    prereact_arr[i] = ((long)height * (long)audio_input) / 1023L; // TRANSLATE AUDIO LEVEL TO NUMBER OF LEDs  | 
 | 127 | + | 
 | 128 | +    if (prereact_arr[i] > react_arr[i]) // ONLY ADJUST LEVEL OF LED IF LEVEL HIGHER THAN CURRENT LEVEL  | 
 | 129 | +      react_arr[i] = prereact_arr[i];  | 
 | 130 | + | 
 | 131 | +    Serial.print(audio_input);  | 
 | 132 | +    Serial.print(" -> ");  | 
 | 133 | +    Serial.println(prereact_arr[i]);  | 
 | 134 | +  }  | 
 | 135 | +}  | 
 | 136 | + | 
 | 137 | + | 
 | 138 | + | 
 | 139 | +// FUNCTION TO VISUALIZE WITH A SINGLE LEVEL  | 
 | 140 | +void singleLevel()  | 
 | 141 | +{  | 
 | 142 | +  readMSGEQ7();  | 
 | 143 | + | 
 | 144 | +  for (int i = 0; i < 7; i++)  | 
 | 145 | +    convertSingle(i);  | 
 | 146 | + | 
 | 147 | +  singleRainbow(); // APPLY COLOR  | 
 | 148 | + | 
 | 149 | +  k = k - wheel_speed; // SPEED OF COLOR WHEEL  | 
 | 150 | +  if (k < 0) // RESET COLOR WHEEL  | 
 | 151 | +    k = 255;  | 
 | 152 | + | 
 | 153 | +  // REMOVE LEDs  | 
 | 154 | +  decay_check++;  | 
 | 155 | +  if (decay_check > decay)  | 
 | 156 | +  {  | 
 | 157 | +    decay_check = 0;  | 
 | 158 | +    for (int x = 0; x < 7; x++)  | 
 | 159 | +    {  | 
 | 160 | +      if (react_arr[x] > 0)  | 
 | 161 | +        react_arr[x]--;  | 
 | 162 | +    }  | 
 | 163 | +  }  | 
 | 164 | +}  | 
 | 165 | + | 
 | 166 | + | 
 | 167 | + | 
 | 168 | +void setup() {  | 
 | 169 | +  // SPECTRUM SETUP  | 
 | 170 | +  pinMode(audio1, INPUT);  | 
 | 171 | +  pinMode(audio2, INPUT);  | 
 | 172 | +  pinMode(strobe, OUTPUT);  | 
 | 173 | +  pinMode(reset, OUTPUT);  | 
 | 174 | +  digitalWrite(reset, LOW);  | 
 | 175 | +  digitalWrite(strobe, HIGH);  | 
 | 176 | +    | 
 | 177 | +  matrix.begin();  | 
 | 178 | +  matrix.setTextWrap(false);  | 
 | 179 | +  matrix.setBrightness(5);  | 
 | 180 | +  matrix.setTextColor(colors[0]);  | 
 | 181 | + | 
 | 182 | +  // SERIAL AND INPUT SETUP  | 
 | 183 | +  Serial.begin(115200);  | 
 | 184 | +  Serial.println("\nListening...");  | 
 | 185 | +}  | 
 | 186 | + | 
 | 187 | + | 
 | 188 | + | 
 | 189 | +void loop()  | 
 | 190 | +{    | 
 | 191 | +  singleLevel();  | 
 | 192 | +  //doubleLevel();  | 
 | 193 | +  //delay(1);  | 
 | 194 | +}  | 
0 commit comments