
#include <FrequencyTimer2.h>  //librera para producir interrupciones por tiempo


// col[xx] of leds = pin yy on led matrix
int columnas[30] = {50, 26, 52, 53, 30, 51, 32, 49, 47, 22, 45, 24, 43, 41, 19, 39, 18, 17, 35, 16, 33, 15, 02, 29, 03, 27, 04, 05, 23, 06};


// row[xx] of leds = pin yy on led matrix
int filas[7] = {48, 44, 42, 38, 46, 40, 36};
int vumetro[30];

int row=0;

void setup() {
  // sets the pins as output
  for (int i = 0; i < 30; i++) {
    pinMode(columnas[i], OUTPUT);
  }
  for (int i = 0; i < 7; i++) {
    pinMode(filas[i], OUTPUT);
  }


  // Turn off toggling of pin 11
  FrequencyTimer2::disable();
  // Set refresh rate (interrupt timeout period)
  FrequencyTimer2::setPeriod(3000);
  // Set interrupt routine to be called
  FrequencyTimer2::setOnOverflow(display);


}

void loop() {
  int sensor = analogRead(A13)/33;
  for(int i=0;i<30;i++){
    if(i<sensor){
      vumetro[i]=1;
    }else{
      vumetro[i]=0;
    }
    delay(5);
  }
}

// Interrupt routine
void display() {
  digitalWrite(filas[row], HIGH);  // Turn whole previous row off
  row++;
  if (row >6) {
    row = 0;
  }
  
  for(int ss=0;ss<30;ss++){
    if(vumetro[ss]==1 ){
      digitalWrite(columnas[ss], HIGH);  // Turn on this led
    }
    else {
      digitalWrite(columnas[ss], LOW); // Turn off this led
    }
  }		

  digitalWrite(filas[row], LOW); // Turn whole row on at once (for equal lighting times)
}
