 {
     for(int i=0; i<=10; i++){
         lcd_init();
-        delay(200);
+        //delay(200);
         lcd.print(value);
-        delay(200);
+        //delay(200);
     }
 }
+
+void hc138sacn(byte r){
+  digitalWrite(RowA,(r & 0x01));
+  digitalWrite(RowB,(r & 0x02));
+  digitalWrite(RowC,(r & 0x04));
+  digitalWrite(RowD,(r & 0x08));
+
+}
+
+

#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 6

int sensorValue;
int average;
int counter = 0;
boolean clapMeterOn = false;

int sensor_2 = 0;
SoftwareSerial lcd(99, LCD_OUT);


#define DBNORM 70

void setHistogram(int value){

     int normValue = value/DBNORM;
     normValue = min(normValue*2,32);
     //Serial.println(hz.size);
     
     for (int i=0;i<64;i++){
         hz1[i] = 0x00; 
     }
     
     for (int i=0;i<64;i++){
     	 if (i<normValue){
     	     hz1[i] = 0xFF;
     }
         else if(i>32 && i<normValue+32){
     	     hz1[i] = 0xFF;
     	 }
         else{
             hz1[i] = 0x00;
         }
	 }
     

     for (int i=0;i<64;i++){
      Serial.print(hz1[i],HEX); 
     }
}
void setup()
{

  
    Serial.begin(9600);
    pins_init();
    //Serial.println("HHHA");
    pinMode(LCD_OUT, OUTPUT);
    lcd.begin(9600);
  
    lcd_init();
    lcd.print("HOLA");

     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);

//    sensor = 300;
    sensor_2 = 300;
    if(min(sensor,sensor_2) > 0)
    {
        sensorValue = max(sensor, sensor_2);
        setHistogram(sensorValue);
  //SPI.begin();
  //delay(100);

  for(row=0;row<16;row++){
       for (int i=0;i<2;i++){
         SPI.transfer(~(hz1[i*32+row*2]));
         SPI.transfer(~(hz1[i*32+row*2+1]));
  }
  digitalWrite(OE,HIGH);
  hc138sacn(row);
  digitalWrite(STB,LOW);
  digitalWrite(STB,HIGH);
  delayMicroseconds(500);
  digitalWrite(OE,LOW);
  delayMicroseconds(500);
  
  }
  
  Serial.print("sensorValue ");
  Serial.println(sensorValue);
       
    if(sensorValue > THRESHOLD_GREEN)
        {
            turnOnLED(GREEN);

            if(counter==0){
                //Serial.println("********************* INICIO APLAUSOMETRO");
            }
            clapMeterOn = true;
            clapMeter = clapMeter + sensorValue;
