Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int spectrumStrobe = 4; // Strobe Pin
- int spectrumReset = 5; // Reset Pin
- int spectrumL[7]; // Arrays for band values
- int spectrumR[7];
- int eqBand; // Band counter
- char dataL[50]; // Arrays for data output
- char dataR[50];
- void setup() {
- Serial.begin(115200);
- pinMode(spectrumReset, OUTPUT); // reset
- pinMode(spectrumStrobe, OUTPUT); // strobe
- // This is following page 4 in the datasheet
- digitalWrite(spectrumReset, HIGH); // Set reset high
- digitalWrite(spectrumStrobe, HIGH); // Toggle the strobe pin
- delayMicroseconds(18);
- digitalWrite(spectrumStrobe, LOW);
- delayMicroseconds(18);
- digitalWrite(spectrumReset, LOW); // Set reset low
- digitalWrite(spectrumStrobe, HIGH); // Toggle strobe high again
- delayMicroseconds(18);
- }
- void readMSGEQ7()
- // Function to read 7 band equalizers
- {
- for(eqBand = 0; eqBand < 7; eqBand++)
- {
- digitalWrite(spectrumStrobe, LOW); // Set strobe low to begin reading
- delayMicroseconds(36); // Wait for the output to settle
- spectrumL[eqBand] = analogRead(0); // store left bands
- spectrumR[eqBand] = analogRead(1); // store right bands
- digitalWrite(spectrumStrobe, HIGH); // Set strobe high to bump to next band
- }
- }
- void loop()
- {
- readMSGEQ7();
- // display values of left & right channel bands on serial monitor
- sprintf(dataL, "left: %3d - %3d - %3d - %3d - %3d - %3d - %3d", spectrumL[0], spectrumL[1], spectrumL[2], spectrumL[3], spectrumL[4], spectrumL[5], spectrumL[6]);
- // Display right channel in reverse, so the data output has low frequencies on the outside with high frequencies on the inside
- sprintf(dataR, "%3d - %3d - %3d - %3d - %3d - %3d - %3d: right", spectrumR[6], spectrumR[5], spectrumR[4], spectrumR[3], spectrumR[2], spectrumR[1], spectrumR[0]);
- Serial.print(dataL);
- Serial.print(" | ");
- Serial.print(dataR);
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement