 
 byte *hz;
 
-byte hz1[] =
-{
-  //[16*16]
-0x00,0x00,
-0x04,0x80,
-0x04,0x80,
-0x05,0xFE,
-0x09,0x02,
-0x0A,0x04,
-0x18,0x20,
-0x28,0x20,
-0x08,0xA8,
-0x08,0xA4,
-0x09,0x24,
-0x09,0x22,
-0x0A,0x22,
-0x08,0x20,
-0x08,0xE0,
-0x00,0x00,
-  //[16*16]
-0x00,0x00,0x10,0x00,0x11,0xF8,0x10,0x08,0x7C,0x10,0x24,0x20,0x24,0x20,0x25,0xFC,
-0x44,0x20,0x24,0x20,0x18,0x20,0x08,0x20,0x14,0x20,0x24,0x20,0x40,0xE0,0x00,0x00
-};
-
-
 int sensorValue;
 
 int average;

#include <SoftwareSerial.h>

#define SOUND_SENSOR A0
#define SOUND_SENSOR_2 A2
#define GREEN 2      // the number of the LED pin
#define RED 3
#define THRESHOLD_GREEN 200//The threshold to turn the led on 400.00*5/1024 = 1.95v
#define THRESHOLD_RED 500
#define LCD_OUT 8

#include <SPI.h>
#include "bars.h"

#define RowA 2
#define RowB 3

     int normValue = value/DBNORM;
     normValue = min(normValue*2,32);
     if (normValue == 0){
      hz = zero;
     }
     else if (normValue == 1){
      hz = one;
     }
     else if (normValue == 2){
      hz = two;
     }
     else if (normValue == 3){
      hz = three;
     }
     else if (normValue == 4){
      hz = four;
     }
     else if (normValue == 5){
      hz = five;
     }
     else if (normValue == 6){
      hz = six;
     }
     else if (normValue == 7){
      hz = seven;
     }
     else if (normValue == 8){
      hz = eight;
     }
     else if (normValue == 9){
      hz = nine;
     }
     else if (normValue == 10){
      hz = ten;
     }
     else if (normValue == 11){
      hz = eleven;
     }
     else if (normValue == 12){
      hz = twelve;
     }
     else if (normValue == 13){
      hz = thirteen;
     }
     else if (normValue == 14){
      hz = fourteen;
     }
     else if (normValue == 15){
      hz = fifteen;
     }
     else if (normValue == 16){
      hz = sixteen;
     }
     else {
      hz = sixteen;
     }
}
void setup()
{


    Serial.begin(9600);
    pins_init();

    pinMode(LCD_OUT, OUTPUT);
    lcd.begin(9600);
    lcd_init();

    pinMode(RowA, OUTPUT);
    pinMode(RowB, OUTPUT);
    pinMode(RowC, OUTPUT);
    pinMode(RowD, OUTPUT);
    pinMode(OE, OUTPUT);
    pinMode(R1, OUTPUT);
    pinMode(CLK, OUTPUT);
    pinMode(STB, OUTPUT);
    SPI.begin();
    delay(10);

}

void loop()
{

    sensor = analogRead(SOUND_SENSOR);
    sensor_2 = analogRead(SOUND_SENSOR_2);

    if(min(sensor,sensor_2) > 0)
    {
        sensorValue = max(sensor, sensor_2);
        setHistogram(sensorValue);

        for(row=0;row<16;row++){
            for (int i=0;i<2;i++){
                SPI.transfer(~(hz[i*32+row*2]));
                SPI.transfer(~(hz[i*32+row*2+1]));
            }
            digitalWrite(OE,HIGH);
            hc138sacn(row);
            digitalWrite(STB,LOW);
            digitalWrite(STB,HIGH);
            delayMicroseconds(500);
            digitalWrite(OE,LOW);
            delayMicroseconds(500);
        }

        if(sensorValue > THRESHOLD_FAIL)
        {
            clapMeterOn = true;
            clapMeter = clapMeter + sensorValue;
            counter++;
        }
   }
   if (clapMeterOn == true && sensorValue < 50)
   {
        average = clapMeter/counter;
        clapMeterOn = false;
        if (average >= THRESHOLD_WIN)
        {
            Serial.println("WIN");
            for (row=0;row<16;row++){
                for (int i=0;i<2;i++){
                    SPI.transfer(~(win[i*32+row*2]));
                    SPI.transfer(~(win[i*32+row*2+1]));
                }
                digitalWrite(OE,HIGH);
                hc138sacn(row);
                digitalWrite(STB,LOW);
                digitalWrite(STB,HIGH);
                delayMicroseconds(500);
                digitalWrite(OE,LOW);
                delayMicroseconds(500);
            }
        } else if (average >= THRESHOLD_GOOD){
            Serial.println("GOOD");
            for (row=0;row<16;row++){
                for (int i=0;i<2;i++){
                    SPI.transfer(~(good[i*32+row*2]));
                    SPI.transfer(~(good[i*32+row*2+1]));
                }
                digitalWrite(OE,HIGH);
                hc138sacn(row);
                digitalWrite(STB,LOW);
                digitalWrite(STB,HIGH);
                delayMicroseconds(500);
                digitalWrite(OE,LOW);
                delayMicroseconds(500);
            }
         } else {
            Serial.println("FAIL");
            for (row=0;row<16;row++){
                for (int i=0;i<2;i++){
                    SPI.transfer(~(fail[i*32+row*2]));
                    SPI.transfer(~(fail[i*32+row*2+1]));
                }
                digitalWrite(OE,HIGH);
                hc138sacn(row);
                digitalWrite(STB,LOW);
                digitalWrite(STB,HIGH);
                delayMicroseconds(500);
                digitalWrite(OE,LOW);
                delayMicroseconds(500);
            }
        }

        counter = 0;
        clapMeter = 0;
    }

}

void pins_init()
{
    pinMode(SOUND_SENSOR, INPUT);
}

void lcd_init()
