Want more features on Pastebin? Sign Up, it's FREE!
Guest

MSGEQ7 Noise

By: kirash4 on Jan 19th, 2014  |  syntax: C++  |  size: 1.91 KB  |  views: 147  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int spectrumStrobe = 4; // Strobe Pin
  2. int spectrumReset  = 5; // Reset Pin
  3. int spectrumL[7];       // Arrays for band values
  4. int spectrumR[7];
  5. int eqBand;             // Band counter
  6. char dataL[50];         // Arrays for data output
  7. char dataR[50];
  8.  
  9. void setup() {
  10.   Serial.begin(115200);
  11.   pinMode(spectrumReset,       OUTPUT); // reset
  12.   pinMode(spectrumStrobe,      OUTPUT); // strobe
  13.   // This is following page 4 in the datasheet
  14.   digitalWrite(spectrumReset,  HIGH);   // Set reset high
  15.   digitalWrite(spectrumStrobe, HIGH);   // Toggle the strobe pin
  16.   delayMicroseconds(18);
  17.   digitalWrite(spectrumStrobe, LOW);
  18.   delayMicroseconds(18);
  19.   digitalWrite(spectrumReset,  LOW);    // Set reset low
  20.   digitalWrite(spectrumStrobe, HIGH);   // Toggle strobe high again
  21.   delayMicroseconds(18);
  22. }
  23.  
  24. void readMSGEQ7()
  25. // Function to read 7 band equalizers
  26. {
  27.   for(eqBand = 0; eqBand < 7; eqBand++)
  28.   {
  29.     digitalWrite(spectrumStrobe, LOW);  // Set strobe low to begin reading
  30.     delayMicroseconds(36);              // Wait for the output to settle
  31.     spectrumL[eqBand] = analogRead(0);  // store left bands
  32.     spectrumR[eqBand] = analogRead(1);  // store right bands
  33.     digitalWrite(spectrumStrobe, HIGH); // Set strobe high to bump to next band
  34.   }
  35. }
  36.  
  37. void loop()
  38. {
  39.   readMSGEQ7();
  40.   // display values of left & right channel bands on serial monitor
  41.   sprintf(dataL,  "left: %3d - %3d - %3d - %3d - %3d - %3d - %3d", spectrumL[0], spectrumL[1], spectrumL[2], spectrumL[3], spectrumL[4], spectrumL[5], spectrumL[6]);
  42.   // Display right channel in reverse, so the data output has low frequencies on the outside with high frequencies on the inside
  43.   sprintf(dataR, "%3d - %3d - %3d - %3d - %3d - %3d - %3d: right", spectrumR[6], spectrumR[5], spectrumR[4], spectrumR[3], spectrumR[2], spectrumR[1], spectrumR[0]);
  44.  
  45.   Serial.print(dataL);
  46.   Serial.print(" | ");
  47.   Serial.print(dataR);
  48.   Serial.println();
  49. }
clone this paste RAW Paste Data