06 Jun 2012

Circuit: simulate music volume bars

I’m building one by one the sample circuits that comes with the Arduino Starter kit I mentioned before.

The second sample circuit is a very basic one that lights 8 leds. The sample code includes a couple of routines to create different led sequences.

I’ve added my own that simulates a volume EQ bar. It doesn’t react to music it’s just faking it (for now).

    void musicMeterSimulator()
    {
      int delayTime = 80;

      int max_pin = random(7);
      for(int i = 7; i >= max_pin; i--)
      {
        digitalWrite(ledPins[i], HIGH);
        delay(delayTime - 10*i);
      }

      for(int i = max_pin; i <= 7; i++)
      {
        digitalWrite(ledPins[i], LOW);
        delay(delayTime - 10*i);
      }
    }

This is a sample video: