×

SparkFun will be closing on Monday for Memorial Day (5/28). Orders placed after 2pm MT on Friday (5/25) will process and ship out on Tuesday (5/29).

Member #504988

Member Since: January 3, 2014

Country: United States

  • The code example provided on the product page didn’t work for me, but the code found on the top of the forum thread worked like a champ: https://forum.sparkfun.com/viewtopic.php?f=14&t=38253

  • This shield puts the FUN in SparkFun! (Sorry)

    Wanted to share code for newbs like myself who found the examples didn’t work quite like I was expecting. This code uses the same board / LED configuration as SF example, but produces more of a peak level meter.

    A good tip from the linked github repository points out that the A0 and A1 pins are reading left and right channels. The code grabs all 7 frequencies from both channels, adds them up, and lights more LEDs the higher the number.

    One code mod to try is lighting all LEDs just on the highest sum which will typically cause the lights to strobe to the beat. You may need to adjust thisSum ranges according to your card / audio source.

    /************************************************
    This sketch acts like the old peak level indicators
    on stereo equipment. 
    *************************************************/
    
    //Declare Spectrum Shield pin connections
    #define STROBE 4
    #define RESET 6
    #define DC_One A0
    #define DC_Two A1
    
    int Spectrum[7];
    int thisSum;
    byte Band;
    
    void setup() {
      Serial.begin(9600);
    
      //Set LED pin configurations
      pinMode(7, OUTPUT);
      pinMode(8, OUTPUT);
      pinMode(9, OUTPUT);
      pinMode(10, OUTPUT);
      pinMode(11, OUTPUT);
      pinMode(12, OUTPUT);
      pinMode(13, OUTPUT);
    
      //Set spectrum Shield pin configurations
      pinMode(STROBE, OUTPUT);
      pinMode(RESET, OUTPUT);
      pinMode(DC_One, INPUT);
      pinMode(DC_Two, INPUT);  
      digitalWrite(STROBE, HIGH);
      digitalWrite(RESET, HIGH);
    
      //Initialize Spectrum Analyzers
      digitalWrite(STROBE, LOW);
      delay(1);
      digitalWrite(RESET, HIGH);
      delay(1);
      digitalWrite(STROBE, HIGH);
      delay(1);
      digitalWrite(STROBE, LOW);
      delay(1);
      digitalWrite(RESET, LOW);
    }
    
    void loop() {
      thisSum = 0;
    
      // Read in all 7 channels into array
      for(Band=0;Band <7; Band++)
      {
        Spectrum[Band] = (analogRead(0) + analogRead(1) ) >>1; //Read left then right channels then average by dividing by 2
        digitalWrite(STROBE,HIGH);
        digitalWrite(STROBE,LOW);
      }
      // Add up the sum of the output
      for(Band=0;Band <7; Band++) {
        thisSum += Spectrum[Band];
      }
      // Light LEDs according to sum
      // Noise level seems to hover just under 550
      if (thisSum > 550) { digitalWrite(7, HIGH); } else { digitalWrite(7, LOW); }
      if (thisSum > 600) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); }
      if (thisSum > 700) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); }
      if (thisSum > 800) { digitalWrite(10, HIGH); } else { digitalWrite(10, LOW); }
      if (thisSum > 900) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); }
      if (thisSum > 1000) { digitalWrite(12, HIGH); } else { digitalWrite(12, LOW); }
      if (thisSum > 1100) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); }
    }
    

No public wish lists :(